#define ucast_ipv4_encoding_len (2 + sizeof(struct in_addr))
+static int
+pim_encode_unicast_address (uint8_t *buf, struct prefix *p)
+{
+ switch (p->family)
+ {
+ case AF_INET:
+ *(uint8_t *)buf = PIM_MSG_ADDRESS_FAMILY_IPV4; /* notice: AF_INET != PIM_MSG_ADDRESS_FAMILY_IPV4 */
+ ++buf;
+ *(uint8_t *)buf = 0; /* ucast IPv4 native encoding type (RFC 4601: 4.9.1) */
+ ++buf;
+ memcpy (buf, &p->u.prefix4, sizeof (struct in_addr));
+ return ucast_ipv4_encoding_len;
+ break;
+ default:
+ return 0;
+ break;
+ }
+}
+
uint8_t *pim_tlv_append_addrlist_ucast(uint8_t *buf,
const uint8_t *buf_pastend,
struct list *ifconnected)
for (; node; node = listnextnode(node)) {
struct connected *ifc = listgetdata(node);
struct prefix *p = ifc->address;
-
- if (p->family != AF_INET)
- continue;
+ int l_encode;
if ((curr + ucast_ipv4_encoding_len) > buf_pastend)
return 0;
- /* Write encoded unicast IPv4 address */
- *(uint8_t *) curr = PIM_MSG_ADDRESS_FAMILY_IPV4; /* notice: AF_INET != PIM_MSG_ADDRESS_FAMILY_IPV4 */
- ++curr;
- *(uint8_t *) curr = 0; /* ucast IPv4 native encoding type (RFC 4601: 4.9.1) */
- ++curr;
- memcpy(curr, &p->u.prefix4, sizeof(struct in_addr));
- curr += sizeof(struct in_addr);
-
- option_len += ucast_ipv4_encoding_len;
+ l_encode = pim_encode_unicast_address (curr, p);
+ curr += l_encode;
+ option_len += l_encode;
}
if (PIM_DEBUG_PIM_TRACE_DETAIL) {
return 0;
}
-int pim_parse_addr_ucast(const char *ifname, struct in_addr src_addr,
- struct prefix *p,
- const uint8_t *buf,
- int buf_size)
+int
+pim_parse_addr_ucast (struct prefix *p,
+ const uint8_t *buf,
+ int buf_size)
{
const int ucast_encoding_min_len = 3; /* 1 family + 1 type + 1 addr */
const uint8_t *addr;
int type;
if (buf_size < ucast_encoding_min_len) {
- char src_str[100];
- pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
- zlog_warn("%s: unicast address encoding overflow: left=%d needed=%d from %s on %s",
+ zlog_warn("%s: unicast address encoding overflow: left=%d needed=%d",
__PRETTY_FUNCTION__,
- buf_size, ucast_encoding_min_len,
- src_str, ifname);
+ buf_size, ucast_encoding_min_len);
return -1;
}
family = *addr++;
type = *addr++;
+ if (type) {
+ zlog_warn("%s: unknown unicast address encoding type=%d",
+ __PRETTY_FUNCTION__,
+ type);
+ return -2;
+ }
+
switch (family) {
case PIM_MSG_ADDRESS_FAMILY_IPV4:
- if (type) {
- char src_str[100];
- pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
- zlog_warn("%s: unknown unicast address encoding type=%d from %s on %s",
- __PRETTY_FUNCTION__,
- type, src_str, ifname);
- return -2;
- }
-
if ((addr + sizeof(struct in_addr)) > pastend) {
- char src_str[100];
- pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
- zlog_warn("%s: IPv4 unicast address overflow: left=%zd needed=%zu from %s on %s",
+ zlog_warn("%s: IPv4 unicast address overflow: left=%zd needed=%zu",
__PRETTY_FUNCTION__,
- pastend - addr, sizeof(struct in_addr),
- src_str, ifname);
+ pastend - addr, sizeof(struct in_addr));
return -3;
}
break;
default:
{
- char src_str[100];
- pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
- zlog_warn("%s: unknown unicast address encoding family=%d from %s on %s",
+ zlog_warn("%s: unknown unicast address encoding family=%d from",
__PRETTY_FUNCTION__,
- family, src_str, ifname);
+ family);
return -4;
}
}
return addr - buf;
}
-int pim_parse_addr_group(const char *ifname, struct in_addr src_addr,
- struct prefix *p,
- const uint8_t *buf,
- int buf_size)
+int
+pim_parse_addr_group (struct prefix *p,
+ const uint8_t *buf,
+ int buf_size)
{
const int grp_encoding_min_len = 4; /* 1 family + 1 type + 1 reserved + 1 addr */
const uint8_t *addr;
int mask_len;
if (buf_size < grp_encoding_min_len) {
- char src_str[100];
- pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
- zlog_warn("%s: group address encoding overflow: left=%d needed=%d from %s on %s",
+ zlog_warn("%s: group address encoding overflow: left=%d needed=%d",
__PRETTY_FUNCTION__,
- buf_size, grp_encoding_min_len,
- src_str, ifname);
+ buf_size, grp_encoding_min_len);
return -1;
}
switch (family) {
case PIM_MSG_ADDRESS_FAMILY_IPV4:
if (type) {
- char src_str[100];
- pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
- zlog_warn("%s: unknown group address encoding type=%d from %s on %s",
- __PRETTY_FUNCTION__,
- type, src_str, ifname);
+ zlog_warn("%s: unknown group address encoding type=%d from",
+ __PRETTY_FUNCTION__, type);
return -2;
}
if ((addr + sizeof(struct in_addr)) > pastend) {
- char src_str[100];
- pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
- zlog_warn("%s: IPv4 group address overflow: left=%zd needed=%zu from %s on %s",
+ zlog_warn("%s: IPv4 group address overflow: left=%zd needed=%zu from",
__PRETTY_FUNCTION__,
- pastend - addr, sizeof(struct in_addr),
- src_str, ifname);
+ pastend - addr, sizeof(struct in_addr));
return -3;
}
break;
default:
{
- char src_str[100];
- pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
- zlog_warn("%s: unknown group address encoding family=%d from %s on %s",
- __PRETTY_FUNCTION__,
- family, src_str, ifname);
+ zlog_warn("%s: unknown group address encoding family=%d from",
+ __PRETTY_FUNCTION__, family);
return -4;
}
}
return addr - buf;
}
-int pim_parse_addr_source(const char *ifname,
- struct in_addr src_addr,
- struct prefix *p,
- uint8_t *flags,
- const uint8_t *buf,
- int buf_size)
+int
+pim_parse_addr_source(struct prefix *p,
+ uint8_t *flags,
+ const uint8_t *buf,
+ int buf_size)
{
const int src_encoding_min_len = 4; /* 1 family + 1 type + 1 reserved + 1 addr */
const uint8_t *addr;
int mask_len;
if (buf_size < src_encoding_min_len) {
- char src_str[100];
- pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
- zlog_warn("%s: source address encoding overflow: left=%d needed=%d from %s on %s",
+ zlog_warn("%s: source address encoding overflow: left=%d needed=%d",
__PRETTY_FUNCTION__,
- buf_size, src_encoding_min_len,
- src_str, ifname);
+ buf_size, src_encoding_min_len);
return -1;
}
*flags = *addr++;
mask_len = *addr++;
+ if (type) {
+ zlog_warn("%s: unknown source address encoding type=%d: %02x%02x%02x%02x%02x%02x%02x%02x",
+ __PRETTY_FUNCTION__,
+ type,
+ buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
+ return -2;
+ }
+
switch (family) {
case PIM_MSG_ADDRESS_FAMILY_IPV4:
- if (type) {
- char src_str[100];
- pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
- zlog_warn("%s: unknown source address encoding type=%d from %s on %s: %02x%02x%02x%02x%02x%02x%02x%02x",
- __PRETTY_FUNCTION__,
- type, src_str, ifname,
- buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
- return -2;
- }
-
if ((addr + sizeof(struct in_addr)) > pastend) {
- char src_str[100];
- pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
- zlog_warn("%s: IPv4 source address overflow: left=%zd needed=%zu from %s on %s",
+ zlog_warn("%s: IPv4 source address overflow: left=%zd needed=%zu",
__PRETTY_FUNCTION__,
- pastend - addr, sizeof(struct in_addr),
- src_str, ifname);
+ pastend - addr, sizeof(struct in_addr));
return -3;
}
received with any other mask length.
*/
if (p->prefixlen != 32) {
- char src_str[100];
- pim_inet4_dump("<src?>", p->u.prefix4, src_str, sizeof(src_str));
- zlog_warn("%s: IPv4 bad source address mask: %s/%d",
- __PRETTY_FUNCTION__, src_str, p->prefixlen);
+ zlog_warn("%s: IPv4 bad source address mask: %d",
+ __PRETTY_FUNCTION__, p->prefixlen);
return -4;
}
break;
default:
{
- char src_str[100];
- pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
- zlog_warn("%s: unknown source address encoding family=%d from %s on %s: %02x%02x%02x%02x%02x%02x%02x%02x",
+ zlog_warn("%s: unknown source address encoding family=%d: %02x%02x%02x%02x%02x%02x%02x%02x",
__PRETTY_FUNCTION__,
- family, src_str, ifname,
+ family,
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
return -5;
}
/*
Parse ucast addr
*/
- addr_offset = pim_parse_addr_ucast(ifname, src_addr, &tmp,
- addr, pastend - addr);
+ addr_offset = pim_parse_addr_ucast(&tmp, addr, pastend - addr);
if (addr_offset < 1) {
char src_str[100];
pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));