diff options
author | whitespace / reindent <invalid@invalid.invalid> | 2017-07-17 14:03:14 +0200 |
---|---|---|
committer | whitespace / reindent <invalid@invalid.invalid> | 2017-07-17 14:04:07 +0200 |
commit | d62a17aedeb0eebdba98238874bb13d62c48dbf9 (patch) | |
tree | 3b319b1d61c8b85b4d1f06adf8b844bb8a9b5107 /bgpd/bgp_rd.c | |
parent | *: add indent control files (diff) | |
download | frr-d62a17aedeb0eebdba98238874bb13d62c48dbf9.tar.xz frr-d62a17aedeb0eebdba98238874bb13d62c48dbf9.zip |
*: reindentreindent-master-after
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'`
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'bgpd/bgp_rd.c')
-rw-r--r-- | bgpd/bgp_rd.c | 287 |
1 files changed, 132 insertions, 155 deletions
diff --git a/bgpd/bgp_rd.c b/bgpd/bgp_rd.c index 03257a292..fd0169394 100644 --- a/bgpd/bgp_rd.c +++ b/bgpd/bgp_rd.c @@ -36,197 +36,174 @@ #include "bgpd/rfapi/rfapi_backend.h" #endif -u_int16_t -decode_rd_type (u_char *pnt) +u_int16_t decode_rd_type(u_char *pnt) { - u_int16_t v; + u_int16_t v; - v = ((u_int16_t) *pnt++ << 8); + v = ((u_int16_t)*pnt++ << 8); #if ENABLE_BGP_VNC - /* - * VNC L2 stores LHI in lower byte, so omit it - */ - if (v != RD_TYPE_VNC_ETH) - v |= (u_int16_t) *pnt; -#else /* duplicate code for clarity */ - v |= (u_int16_t) *pnt; + /* + * VNC L2 stores LHI in lower byte, so omit it + */ + if (v != RD_TYPE_VNC_ETH) + v |= (u_int16_t)*pnt; +#else /* duplicate code for clarity */ + v |= (u_int16_t)*pnt; #endif - return v; + return v; } -void -encode_rd_type (u_int16_t v, u_char *pnt) +void encode_rd_type(u_int16_t v, u_char *pnt) { - *((u_int16_t *)pnt) = htons(v); + *((u_int16_t *)pnt) = htons(v); } /* type == RD_TYPE_AS */ -void -decode_rd_as (u_char *pnt, struct rd_as *rd_as) +void decode_rd_as(u_char *pnt, struct rd_as *rd_as) { - rd_as->as = (u_int16_t) *pnt++ << 8; - rd_as->as |= (u_int16_t) *pnt++; + rd_as->as = (u_int16_t)*pnt++ << 8; + rd_as->as |= (u_int16_t)*pnt++; - rd_as->val = ((u_int32_t) *pnt++ << 24); - rd_as->val |= ((u_int32_t) *pnt++ << 16); - rd_as->val |= ((u_int32_t) *pnt++ << 8); - rd_as->val |= (u_int32_t) *pnt; + rd_as->val = ((u_int32_t)*pnt++ << 24); + rd_as->val |= ((u_int32_t)*pnt++ << 16); + rd_as->val |= ((u_int32_t)*pnt++ << 8); + rd_as->val |= (u_int32_t)*pnt; } /* type == RD_TYPE_AS4 */ -void -decode_rd_as4 (u_char *pnt, struct rd_as *rd_as) +void decode_rd_as4(u_char *pnt, struct rd_as *rd_as) { - rd_as->as = (u_int32_t) *pnt++ << 24; - rd_as->as |= (u_int32_t) *pnt++ << 16; - rd_as->as |= (u_int32_t) *pnt++ << 8; - rd_as->as |= (u_int32_t) *pnt++; + rd_as->as = (u_int32_t)*pnt++ << 24; + rd_as->as |= (u_int32_t)*pnt++ << 16; + rd_as->as |= (u_int32_t)*pnt++ << 8; + rd_as->as |= (u_int32_t)*pnt++; - rd_as->val = ((u_int16_t) *pnt++ << 8); - rd_as->val |= (u_int16_t) *pnt; + rd_as->val = ((u_int16_t)*pnt++ << 8); + rd_as->val |= (u_int16_t)*pnt; } /* type == RD_TYPE_IP */ -void -decode_rd_ip (u_char *pnt, struct rd_ip *rd_ip) +void decode_rd_ip(u_char *pnt, struct rd_ip *rd_ip) { - memcpy (&rd_ip->ip, pnt, 4); - pnt += 4; + memcpy(&rd_ip->ip, pnt, 4); + pnt += 4; - rd_ip->val = ((u_int16_t) *pnt++ << 8); - rd_ip->val |= (u_int16_t) *pnt; + rd_ip->val = ((u_int16_t)*pnt++ << 8); + rd_ip->val |= (u_int16_t)*pnt; } #if ENABLE_BGP_VNC /* type == RD_TYPE_VNC_ETH */ -void -decode_rd_vnc_eth (u_char *pnt, struct rd_vnc_eth *rd_vnc_eth) +void decode_rd_vnc_eth(u_char *pnt, struct rd_vnc_eth *rd_vnc_eth) { - rd_vnc_eth->type = RD_TYPE_VNC_ETH; - rd_vnc_eth->local_nve_id = pnt[1]; - memcpy (rd_vnc_eth->macaddr.octet, pnt + 2, ETHER_ADDR_LEN); + rd_vnc_eth->type = RD_TYPE_VNC_ETH; + rd_vnc_eth->local_nve_id = pnt[1]; + memcpy(rd_vnc_eth->macaddr.octet, pnt + 2, ETHER_ADDR_LEN); } #endif -int -str2prefix_rd (const char *str, struct prefix_rd *prd) +int str2prefix_rd(const char *str, struct prefix_rd *prd) { - int ret; /* ret of called functions */ - int lret; /* local ret, of this func */ - char *p; - char *p2; - struct stream *s = NULL; - char *half = NULL; - struct in_addr addr; - - s = stream_new (8); - - prd->family = AF_UNSPEC; - prd->prefixlen = 64; - - lret = 0; - p = strchr (str, ':'); - if (! p) - goto out; - - if (! all_digit (p + 1)) - goto out; - - half = XMALLOC (MTYPE_TMP, (p - str) + 1); - memcpy (half, str, (p - str)); - half[p - str] = '\0'; - - p2 = strchr (str, '.'); - - if (! p2) - { - unsigned long as_val; - - if (! all_digit (half)) - goto out; - - as_val = atol(half); - if (as_val > 0xffff) - { - stream_putw (s, RD_TYPE_AS4); - stream_putl (s, as_val); - stream_putw (s, atol (p + 1)); - } - else - { - stream_putw (s, RD_TYPE_AS); - stream_putw (s, as_val); - stream_putl (s, atol (p + 1)); - } - } - else - { - ret = inet_aton (half, &addr); - if (! ret) - goto out; - - stream_putw (s, RD_TYPE_IP); - stream_put_in_addr (s, &addr); - stream_putw (s, atol (p + 1)); - } - memcpy (prd->val, s->data, 8); - lret = 1; + int ret; /* ret of called functions */ + int lret; /* local ret, of this func */ + char *p; + char *p2; + struct stream *s = NULL; + char *half = NULL; + struct in_addr addr; + + s = stream_new(8); + + prd->family = AF_UNSPEC; + prd->prefixlen = 64; + + lret = 0; + p = strchr(str, ':'); + if (!p) + goto out; + + if (!all_digit(p + 1)) + goto out; + + half = XMALLOC(MTYPE_TMP, (p - str) + 1); + memcpy(half, str, (p - str)); + half[p - str] = '\0'; + + p2 = strchr(str, '.'); + + if (!p2) { + unsigned long as_val; + + if (!all_digit(half)) + goto out; + + as_val = atol(half); + if (as_val > 0xffff) { + stream_putw(s, RD_TYPE_AS4); + stream_putl(s, as_val); + stream_putw(s, atol(p + 1)); + } else { + stream_putw(s, RD_TYPE_AS); + stream_putw(s, as_val); + stream_putl(s, atol(p + 1)); + } + } else { + ret = inet_aton(half, &addr); + if (!ret) + goto out; + + stream_putw(s, RD_TYPE_IP); + stream_put_in_addr(s, &addr); + stream_putw(s, atol(p + 1)); + } + memcpy(prd->val, s->data, 8); + lret = 1; out: - if (s) - stream_free (s); - if (half) - XFREE(MTYPE_TMP, half); - return lret; + if (s) + stream_free(s); + if (half) + XFREE(MTYPE_TMP, half); + return lret; } -char * -prefix_rd2str (struct prefix_rd *prd, char *buf, size_t size) +char *prefix_rd2str(struct prefix_rd *prd, char *buf, size_t size) { - u_char *pnt; - u_int16_t type; - struct rd_as rd_as; - struct rd_ip rd_ip; - - if (size < RD_ADDRSTRLEN) - return NULL; - - pnt = prd->val; - - type = decode_rd_type (pnt); - - if (type == RD_TYPE_AS) - { - decode_rd_as (pnt + 2, &rd_as); - snprintf (buf, size, "%u:%d", rd_as.as, rd_as.val); - return buf; - } - else if (type == RD_TYPE_AS4) - { - decode_rd_as4 (pnt + 2, &rd_as); - snprintf (buf, size, "%u:%d", rd_as.as, rd_as.val); - return buf; - } - else if (type == RD_TYPE_IP) - { - decode_rd_ip (pnt + 2, &rd_ip); - snprintf (buf, size, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val); - return buf; - } + u_char *pnt; + u_int16_t type; + struct rd_as rd_as; + struct rd_ip rd_ip; + + if (size < RD_ADDRSTRLEN) + return NULL; + + pnt = prd->val; + + type = decode_rd_type(pnt); + + if (type == RD_TYPE_AS) { + decode_rd_as(pnt + 2, &rd_as); + snprintf(buf, size, "%u:%d", rd_as.as, rd_as.val); + return buf; + } else if (type == RD_TYPE_AS4) { + decode_rd_as4(pnt + 2, &rd_as); + snprintf(buf, size, "%u:%d", rd_as.as, rd_as.val); + return buf; + } else if (type == RD_TYPE_IP) { + decode_rd_ip(pnt + 2, &rd_ip); + snprintf(buf, size, "%s:%d", inet_ntoa(rd_ip.ip), rd_ip.val); + return buf; + } #if ENABLE_BGP_VNC - else if (type == RD_TYPE_VNC_ETH) - { - snprintf(buf, size, "LHI:%d, %02x:%02x:%02x:%02x:%02x:%02x", - *(pnt+1), /* LHI */ - *(pnt+2), /* MAC[0] */ - *(pnt+3), - *(pnt+4), - *(pnt+5), - *(pnt+6), - *(pnt+7)); - - return buf; - } + else if (type == RD_TYPE_VNC_ETH) { + snprintf(buf, size, "LHI:%d, %02x:%02x:%02x:%02x:%02x:%02x", + *(pnt + 1), /* LHI */ + *(pnt + 2), /* MAC[0] */ + *(pnt + 3), *(pnt + 4), *(pnt + 5), *(pnt + 6), + *(pnt + 7)); + + return buf; + } #endif - return NULL; + return NULL; } |