summaryrefslogtreecommitdiff
path: root/usr.sbin/ldpd/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/ldpd/init.c')
-rw-r--r--usr.sbin/ldpd/init.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/usr.sbin/ldpd/init.c b/usr.sbin/ldpd/init.c
index a4f6e1864cb..cad15769b03 100644
--- a/usr.sbin/ldpd/init.c
+++ b/usr.sbin/ldpd/init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init.c,v 1.23 2016/05/23 16:20:59 renato Exp $ */
+/* $OpenBSD: init.c,v 1.24 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -38,14 +38,14 @@
extern struct ldpd_conf *leconf;
-int gen_init_prms_tlv(struct ibuf *, struct nbr *, u_int16_t);
-int tlv_decode_opt_init_prms(char *, u_int16_t);
+int gen_init_prms_tlv(struct ibuf *, struct nbr *, uint16_t);
+int tlv_decode_opt_init_prms(char *, uint16_t);
void
send_init(struct nbr *nbr)
{
struct ibuf *buf;
- u_int16_t size;
+ uint16_t size;
log_debug("%s: lsr-id %s", __func__, inet_ntoa(nbr->id));
@@ -63,7 +63,7 @@ send_init(struct nbr *nbr)
}
int
-recv_init(struct nbr *nbr, char *buf, u_int16_t len)
+recv_init(struct nbr *nbr, char *buf, uint16_t len)
{
struct ldp_msg init;
struct sess_prms_tlv sess;
@@ -71,16 +71,19 @@ recv_init(struct nbr *nbr, char *buf, u_int16_t len)
log_debug("%s: lsr-id %s", __func__, inet_ntoa(nbr->id));
- bcopy(buf, &init, sizeof(init));
-
- buf += sizeof(struct ldp_msg);
- len -= sizeof(struct ldp_msg);
+ memcpy(&init, buf, sizeof(init));
+ buf += LDP_MSG_SIZE;
+ len -= LDP_MSG_SIZE;
if (len < SESS_PRMS_SIZE) {
session_shutdown(nbr, S_BAD_MSG_LEN, init.msgid, init.type);
return (-1);
}
- bcopy(buf, &sess, sizeof(sess));
+ memcpy(&sess, buf, sizeof(sess));
+ if (ntohs(sess.keepalive_time) < MIN_KEEPALIVE) {
+ session_shutdown(nbr, S_KEEPALIVE_BAD, init.msgid, init.type);
+ return (-1);
+ }
if (ntohs(sess.length) != SESS_PRMS_SIZE - TLV_HDR_LEN) {
session_shutdown(nbr, S_BAD_TLV_LEN, init.msgid, init.type);
@@ -120,16 +123,13 @@ recv_init(struct nbr *nbr, char *buf, u_int16_t len)
}
int
-gen_init_prms_tlv(struct ibuf *buf, struct nbr *nbr, u_int16_t size)
+gen_init_prms_tlv(struct ibuf *buf, struct nbr *nbr, uint16_t size)
{
struct sess_prms_tlv parms;
- /* We want just the size of the value */
- size -= TLV_HDR_LEN;
-
- bzero(&parms, sizeof(parms));
+ memset(&parms, 0, sizeof(parms));
parms.type = htons(TLV_TYPE_COMMONSESSION);
- parms.length = htons(size);
+ parms.length = htons(size - TLV_HDR_LEN);
parms.proto_version = htons(LDP_VERSION);
parms.keepalive_time = htons(nbr_get_keepalive(nbr->raddr));
parms.reserved = 0;
@@ -142,14 +142,14 @@ gen_init_prms_tlv(struct ibuf *buf, struct nbr *nbr, u_int16_t size)
}
int
-tlv_decode_opt_init_prms(char *buf, u_int16_t len)
+tlv_decode_opt_init_prms(char *buf, uint16_t len)
{
struct tlv tlv;
- int cons = 0;
- u_int16_t tlv_len;
+ uint16_t tlv_len;
+ int total = 0;
while (len >= sizeof(tlv)) {
- bcopy(buf, &tlv, sizeof(tlv));
+ memcpy(&tlv, buf, sizeof(tlv));
tlv_len = ntohs(tlv.length);
switch (ntohs(tlv.type)) {
case TLV_TYPE_ATMSESSIONPAR: