From 54dd61227352dd1dd4db4fe76dbf7d2e92522e74 Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Wed, 21 Mar 2012 10:00:07 -0700 Subject: lib: Tweaks to linked list macros * lib/linklist.h - Change the listnextnode, listhead and listtail macros so that they allow the list pointer to be NULL. - Modify the ALL_LIST_ELEMENTS* macros such that they clear the data pointer at the beginning and end of the loop. From: Josh Bailey Signed-off-by: Avneesh Sachdev Signed-off-by: David Lamparter --- lib/linklist.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/linklist.h b/lib/linklist.h index cc6867cd..f0ae3625 100644 --- a/lib/linklist.h +++ b/lib/linklist.h @@ -54,9 +54,9 @@ struct list void (*del) (void *val); }; -#define listnextnode(X) ((X)->next) -#define listhead(X) ((X)->head) -#define listtail(X) ((X)->tail) +#define listnextnode(X) ((X) ? ((X)->next) : NULL) +#define listhead(X) ((X) ? ((X)->head) : NULL) +#define listtail(X) ((X) ? ((X)->tail) : NULL) #define listcount(X) ((X)->count) #define list_isempty(X) ((X)->head == NULL && (X)->tail == NULL) #define listgetdata(X) (assert((X)->data != NULL), (X)->data) @@ -88,10 +88,10 @@ extern void list_add_list (struct list *, struct list *); * It is safe to delete the listnode using this macro. */ #define ALL_LIST_ELEMENTS(list,node,nextnode,data) \ - (node) = listhead(list); \ + (node) = listhead(list), ((data) = NULL); \ (node) != NULL && \ ((data) = listgetdata(node),(nextnode) = listnextnode(node), 1); \ - (node) = (nextnode) + (node) = (nextnode), ((data) = NULL) /* read-only list iteration macro. * Usage: as per ALL_LIST_ELEMENTS, but not safe to delete the listnode Only @@ -100,9 +100,9 @@ extern void list_add_list (struct list *, struct list *); * of previous macro. */ #define ALL_LIST_ELEMENTS_RO(list,node,data) \ - (node) = listhead(list); \ + (node) = listhead(list), ((data) = NULL);\ (node) != NULL && ((data) = listgetdata(node), 1); \ - (node) = listnextnode(node) + (node) = listnextnode(node), ((data) = NULL) /* these *do not* cleanup list nodes and referenced data, as the functions * do - these macros simply {de,at}tach a listnode from/to a list. -- cgit v1.2.1 From bed930fd70742af5ae138e0a5ee629dda296ea36 Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Wed, 21 Mar 2012 10:22:19 -0700 Subject: lib: add support for keyed-hashing with MD5 * lib/md5.[ch] Add implementation of HMAC-MD5 from RFC 2104. From: Josh Bailey Signed-off-by: Avneesh Sachdev Signed-off-by: David Lamparter --- lib/md5.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/md5.h | 4 ++++ 2 files changed, 77 insertions(+) (limited to 'lib') diff --git a/lib/md5.c b/lib/md5.c index 894de648..2fc36e17 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -298,3 +298,76 @@ static void md5_calc(const uint8_t *b64, md5_ctxt * ctxt) ctxt->md5_stc += C; ctxt->md5_std += D; } + +/* From RFC 2104 */ +void +hmac_md5(text, text_len, key, key_len, digest) +unsigned char* text; /* pointer to data stream */ +int text_len; /* length of data stream */ +unsigned char* key; /* pointer to authentication key */ +int key_len; /* length of authentication key */ +caddr_t digest; /* caller digest to be filled in */ + +{ + MD5_CTX context; + unsigned char k_ipad[65]; /* inner padding - + * key XORd with ipad + */ + unsigned char k_opad[65]; /* outer padding - + * key XORd with opad + */ + unsigned char tk[16]; + int i; + /* if key is longer than 64 bytes reset it to key=MD5(key) */ + if (key_len > 64) { + + MD5_CTX tctx; + + MD5Init(&tctx); + MD5Update(&tctx, key, key_len); + MD5Final(tk, &tctx); + + key = tk; + key_len = 16; + } + + /* + * the HMAC_MD5 transform looks like: + * + * MD5(K XOR opad, MD5(K XOR ipad, text)) + * + * where K is an n byte key + * ipad is the byte 0x36 repeated 64 times + * opad is the byte 0x5c repeated 64 times + * and text is the data being protected + */ + + /* start out by storing key in pads */ + bzero( k_ipad, sizeof k_ipad); + bzero( k_opad, sizeof k_opad); + bcopy( key, k_ipad, key_len); + bcopy( key, k_opad, key_len); + + /* XOR key with ipad and opad values */ + for (i=0; i<64; i++) { + k_ipad[i] ^= 0x36; + k_opad[i] ^= 0x5c; + } + /* + * perform inner MD5 + */ + MD5Init(&context); /* init context for 1st + * pass */ + MD5Update(&context, k_ipad, 64); /* start with inner pad */ + MD5Update(&context, text, text_len); /* then text of datagram */ + MD5Final(digest, &context); /* finish up 1st pass */ + /* + * perform outer MD5 + */ + MD5Init(&context); /* init context for 2nd + * pass */ + MD5Update(&context, k_opad, 64); /* start with outer pad */ + MD5Update(&context, digest, 16); /* then results of 1st + * hash */ + MD5Final(digest, &context); /* finish up 2nd pass */ +} diff --git a/lib/md5.h b/lib/md5.h index 89b9a320..a03bf22a 100644 --- a/lib/md5.h +++ b/lib/md5.h @@ -82,4 +82,8 @@ do { \ md5_result((x), (y)); \ } while (0) +/* From RFC 2104 */ +void hmac_md5(unsigned char* text, int text_len, unsigned char* key, + int key_len, caddr_t digest); + #endif /* ! _LIBZEBRA_MD5_H_*/ -- cgit v1.2.1 From d531050b7bf0f93d4d29a7a2f7b745641778b483 Mon Sep 17 00:00:00 2001 From: Subbaiah Venkata Date: Sat, 24 Mar 2012 13:10:19 -0700 Subject: lib: add stream_set_endp() * lib/stream.[ch]: - Add stream_set_endp(). This can be used to trim data (for example, padding) at the end of a stream. - Fix swapped 'getp' and 'endp' parameters in STREAM_WARN_OFFSETS. From: Subbaiah Venkata Signed-off-by: Avneesh Sachdev Signed-off-by: David Lamparter --- lib/stream.c | 20 +++++++++++++++++--- lib/stream.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/stream.c b/lib/stream.c index 983330ff..b226a25e 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -52,7 +52,7 @@ * using stream_put..._at() functions. */ #define STREAM_WARN_OFFSETS(S) \ - zlog_warn ("&(struct stream): %p, size: %lu, endp: %lu, getp: %lu\n", \ + zlog_warn ("&(struct stream): %p, size: %lu, getp: %lu, endp: %lu\n", \ (S), \ (unsigned long) (S)->size, \ (unsigned long) (S)->getp, \ @@ -214,6 +214,20 @@ stream_set_getp (struct stream *s, size_t pos) s->getp = pos; } +void +stream_set_endp (struct stream *s, size_t pos) +{ + STREAM_VERIFY_SANE(s); + + if (!GETP_VALID (s, pos)) + { + STREAM_BOUND_WARN (s, "set endp"); + pos = s->endp; + } + + s->endp = pos; +} + /* Forward pointer. */ void stream_forward_getp (struct stream *s, size_t size) @@ -934,9 +948,9 @@ stream_fifo_pop (struct stream_fifo *fifo) if (fifo->head == NULL) fifo->tail = NULL; - } - fifo->count--; + fifo->count--; + } return s; } diff --git a/lib/stream.h b/lib/stream.h index 3e4ba7b4..f10aa6d4 100644 --- a/lib/stream.h +++ b/lib/stream.h @@ -146,6 +146,7 @@ extern size_t stream_get_size (struct stream *); extern u_char *stream_get_data (struct stream *); extern void stream_set_getp (struct stream *, size_t); +extern void stream_set_endp (struct stream *, size_t); extern void stream_forward_getp (struct stream *, size_t); extern void stream_forward_endp (struct stream *, size_t); -- cgit v1.2.1 From 3f045a08812525505e165deea99a79447b44506b Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Sat, 24 Mar 2012 08:35:20 -0700 Subject: isisd: add Google's changes to IS-IS --- lib/memtypes.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/memtypes.c b/lib/memtypes.c index 59020671..69beb1c9 100644 --- a/lib/memtypes.c +++ b/lib/memtypes.c @@ -242,6 +242,8 @@ struct memory_list memory_list_isis[] = { MTYPE_ISIS_ROUTE_INFO, "ISIS route info" }, { MTYPE_ISIS_NEXTHOP, "ISIS nexthop" }, { MTYPE_ISIS_NEXTHOP6, "ISIS nexthop6" }, + { MTYPE_ISIS_DICT, "ISIS dictionary" }, + { MTYPE_ISIS_DICT_NODE, "ISIS dictionary node" }, { -1, NULL }, }; -- cgit v1.2.1 From 2dd04c5dc8b5a09cce1c251361fa58f26398fd9f Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Wed, 21 Mar 2012 10:37:03 -0700 Subject: lib: Tweak to if_delete_retain() * lib/if.c: Change if_delete_retain() to delete all connected addresses, but to not free the list that holds them. Free the list just before the interface structure itself is freed, in if_delete(). --- lib/if.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/if.c b/lib/if.c index 86f754b6..e9ef50b7 100644 --- a/lib/if.c +++ b/lib/if.c @@ -146,7 +146,7 @@ if_delete_retain (struct interface *ifp) (*if_master.if_delete_hook) (ifp); /* Free connected address list */ - list_delete (ifp->connected); + list_delete_all_node (ifp->connected); } /* Delete and free interface structure. */ @@ -157,6 +157,8 @@ if_delete (struct interface *ifp) if_delete_retain(ifp); + list_free (ifp->connected); + XFREE (MTYPE_IF, ifp); } -- cgit v1.2.1 From 51d4ef832c1e58150325630e25c442866e5a6cf5 Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Wed, 21 Mar 2012 17:13:39 -0700 Subject: zebra: include hardware addr in if up/down messages Change interface up/down notification messages to also include the hardware address of the interface. The format of these messages is now identical to the interface add message -- move the serialization code to common functions. * lib/zclient.c: Modify zebra_interface_if_set_value() to also parse the hardware address. Invoke it from zebra_interface_add_read() and and zebra_interface_state_read(). * zebra/zserv.c: Add zserv_encode_interface(). Invoke it from zserv_interface_add(), zserv_interface_delete() and zserv_interface_update(). --- lib/zclient.c | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) (limited to 'lib') diff --git a/lib/zclient.c b/lib/zclient.c index 52a3627d..85aa737e 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -611,24 +611,8 @@ zebra_interface_add_read (struct stream *s) /* Lookup/create interface by name. */ ifp = if_get_by_name_len (ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ)); - /* Read interface's index. */ - ifp->ifindex = stream_getl (s); + zebra_interface_if_set_value (s, ifp); - /* Read interface's value. */ - ifp->status = stream_getc (s); - ifp->flags = stream_getq (s); - ifp->metric = stream_getl (s); - ifp->mtu = stream_getl (s); - ifp->mtu6 = stream_getl (s); - ifp->bandwidth = stream_getl (s); -#ifdef HAVE_STRUCT_SOCKADDR_DL - stream_get (&ifp->sdl, s, sizeof (ifp->sdl)); -#else - ifp->hw_addr_len = stream_getl (s); - if (ifp->hw_addr_len) - stream_get (ifp->hw_addr, s, ifp->hw_addr_len); -#endif /* HAVE_STRUCT_SOCKADDR_DL */ - return ifp; } @@ -656,16 +640,7 @@ zebra_interface_state_read (struct stream *s) if (! ifp) return NULL; - /* Read interface's index. */ - ifp->ifindex = stream_getl (s); - - /* Read interface's value. */ - ifp->status = stream_getc (s); - ifp->flags = stream_getq (s); - ifp->metric = stream_getl (s); - ifp->mtu = stream_getl (s); - ifp->mtu6 = stream_getl (s); - ifp->bandwidth = stream_getl (s); + zebra_interface_if_set_value (s, ifp); return ifp; } @@ -715,6 +690,13 @@ zebra_interface_if_set_value (struct stream *s, struct interface *ifp) ifp->mtu = stream_getl (s); ifp->mtu6 = stream_getl (s); ifp->bandwidth = stream_getl (s); +#ifdef HAVE_STRUCT_SOCKADDR_DL + stream_get (&ifp->sdl, s, sizeof (ifp->sdl)); +#else + ifp->hw_addr_len = stream_getl (s); + if (ifp->hw_addr_len) + stream_get (ifp->hw_addr, s, ifp->hw_addr_len); +#endif /* HAVE_STRUCT_SOCKADDR_DL */ } static int -- cgit v1.2.1