pim_tlv.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. /*
  2. PIM for Quagga
  3. Copyright (C) 2008 Everton da Silva Marques
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; see the file COPYING; if not, write to the
  14. Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  15. MA 02110-1301 USA
  16. $QuaggaId: $Format:%an, %ai, %h$ $
  17. */
  18. #include <zebra.h>
  19. #include "log.h"
  20. #include "prefix.h"
  21. #include "pimd.h"
  22. #include "pim_int.h"
  23. #include "pim_tlv.h"
  24. #include "pim_str.h"
  25. #include "pim_msg.h"
  26. uint8_t *pim_tlv_append_uint16(uint8_t *buf,
  27. const uint8_t *buf_pastend,
  28. uint16_t option_type,
  29. uint16_t option_value)
  30. {
  31. uint16_t option_len = 2;
  32. if ((buf + PIM_TLV_OPTION_SIZE(option_len)) > buf_pastend)
  33. return NULL;
  34. *(uint16_t *) buf = htons(option_type);
  35. buf += 2;
  36. *(uint16_t *) buf = htons(option_len);
  37. buf += 2;
  38. *(uint16_t *) buf = htons(option_value);
  39. buf += option_len;
  40. return buf;
  41. }
  42. uint8_t *pim_tlv_append_2uint16(uint8_t *buf,
  43. const uint8_t *buf_pastend,
  44. uint16_t option_type,
  45. uint16_t option_value1,
  46. uint16_t option_value2)
  47. {
  48. uint16_t option_len = 4;
  49. if ((buf + PIM_TLV_OPTION_SIZE(option_len)) > buf_pastend)
  50. return NULL;
  51. *(uint16_t *) buf = htons(option_type);
  52. buf += 2;
  53. *(uint16_t *) buf = htons(option_len);
  54. buf += 2;
  55. *(uint16_t *) buf = htons(option_value1);
  56. buf += 2;
  57. *(uint16_t *) buf = htons(option_value2);
  58. buf += 2;
  59. return buf;
  60. }
  61. uint8_t *pim_tlv_append_uint32(uint8_t *buf,
  62. const uint8_t *buf_pastend,
  63. uint16_t option_type,
  64. uint32_t option_value)
  65. {
  66. uint16_t option_len = 4;
  67. if ((buf + PIM_TLV_OPTION_SIZE(option_len)) > buf_pastend)
  68. return NULL;
  69. *(uint16_t *) buf = htons(option_type);
  70. buf += 2;
  71. *(uint16_t *) buf = htons(option_len);
  72. buf += 2;
  73. pim_write_uint32(buf, option_value);
  74. buf += option_len;
  75. return buf;
  76. }
  77. #define ucast_ipv4_encoding_len (2 + sizeof(struct in_addr))
  78. uint8_t *pim_tlv_append_addrlist_ucast(uint8_t *buf,
  79. const uint8_t *buf_pastend,
  80. struct list *ifconnected)
  81. {
  82. struct listnode *node;
  83. uint16_t option_len = 0;
  84. uint8_t *curr;
  85. node = listhead(ifconnected);
  86. /* Empty address list ? */
  87. if (!node) {
  88. return buf;
  89. }
  90. /* Skip first address (primary) */
  91. node = listnextnode(node);
  92. /* Scan secondary address list */
  93. curr = buf + 4; /* skip T and L */
  94. for (; node; node = listnextnode(node)) {
  95. struct connected *ifc = listgetdata(node);
  96. struct prefix *p = ifc->address;
  97. if (p->family != AF_INET)
  98. continue;
  99. if ((curr + ucast_ipv4_encoding_len) > buf_pastend)
  100. return 0;
  101. /* Write encoded unicast IPv4 address */
  102. *(uint8_t *) curr = PIM_MSG_ADDRESS_FAMILY_IPV4; /* notice: AF_INET != PIM_MSG_ADDRESS_FAMILY_IPV4 */
  103. ++curr;
  104. *(uint8_t *) curr = 0; /* ucast IPv4 native encoding type (RFC 4601: 4.9.1) */
  105. ++curr;
  106. memcpy(curr, &p->u.prefix4, sizeof(struct in_addr));
  107. curr += sizeof(struct in_addr);
  108. option_len += ucast_ipv4_encoding_len;
  109. }
  110. if (PIM_DEBUG_PIM_TRACE) {
  111. zlog_debug("%s: number of encoded secondary unicast IPv4 addresses: %zu",
  112. __PRETTY_FUNCTION__,
  113. option_len / ucast_ipv4_encoding_len);
  114. }
  115. if (option_len < 1) {
  116. /* Empty secondary unicast IPv4 address list */
  117. return buf;
  118. }
  119. /*
  120. * Write T and L
  121. */
  122. *(uint16_t *) buf = htons(PIM_MSG_OPTION_TYPE_ADDRESS_LIST);
  123. *(uint16_t *) (buf + 2) = htons(option_len);
  124. return curr;
  125. }
  126. static int check_tlv_length(const char *label, const char *tlv_name,
  127. const char *ifname, struct in_addr src_addr,
  128. int correct_len, int option_len)
  129. {
  130. if (option_len != correct_len) {
  131. char src_str[100];
  132. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  133. zlog_warn("%s: PIM hello %s TLV with incorrect value size=%d correct=%d from %s on interface %s",
  134. label, tlv_name,
  135. option_len, correct_len,
  136. src_str, ifname);
  137. return -1;
  138. }
  139. return 0;
  140. }
  141. static void check_tlv_redefinition_uint16(const char *label, const char *tlv_name,
  142. const char *ifname, struct in_addr src_addr,
  143. pim_hello_options options,
  144. pim_hello_options opt_mask,
  145. uint16_t new, uint16_t old)
  146. {
  147. if (PIM_OPTION_IS_SET(options, opt_mask)) {
  148. char src_str[100];
  149. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  150. zlog_warn("%s: PIM hello TLV redefined %s=%u old=%u from %s on interface %s",
  151. label, tlv_name,
  152. new, old,
  153. src_str, ifname);
  154. }
  155. }
  156. static void check_tlv_redefinition_uint32(const char *label, const char *tlv_name,
  157. const char *ifname, struct in_addr src_addr,
  158. pim_hello_options options,
  159. pim_hello_options opt_mask,
  160. uint32_t new, uint32_t old)
  161. {
  162. if (PIM_OPTION_IS_SET(options, opt_mask)) {
  163. char src_str[100];
  164. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  165. zlog_warn("%s: PIM hello TLV redefined %s=%u old=%u from %s on interface %s",
  166. label, tlv_name,
  167. new, old,
  168. src_str, ifname);
  169. }
  170. }
  171. static void check_tlv_redefinition_uint32_hex(const char *label, const char *tlv_name,
  172. const char *ifname, struct in_addr src_addr,
  173. pim_hello_options options,
  174. pim_hello_options opt_mask,
  175. uint32_t new, uint32_t old)
  176. {
  177. if (PIM_OPTION_IS_SET(options, opt_mask)) {
  178. char src_str[100];
  179. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  180. zlog_warn("%s: PIM hello TLV redefined %s=%08x old=%08x from %s on interface %s",
  181. label, tlv_name,
  182. new, old,
  183. src_str, ifname);
  184. }
  185. }
  186. int pim_tlv_parse_holdtime(const char *ifname, struct in_addr src_addr,
  187. pim_hello_options *hello_options,
  188. uint16_t *hello_option_holdtime,
  189. uint16_t option_len,
  190. const uint8_t *tlv_curr)
  191. {
  192. const char *label = "holdtime";
  193. if (check_tlv_length(__PRETTY_FUNCTION__, label,
  194. ifname, src_addr,
  195. sizeof(uint16_t), option_len)) {
  196. return -1;
  197. }
  198. check_tlv_redefinition_uint16(__PRETTY_FUNCTION__, label,
  199. ifname, src_addr,
  200. *hello_options, PIM_OPTION_MASK_HOLDTIME,
  201. PIM_TLV_GET_HOLDTIME(tlv_curr),
  202. *hello_option_holdtime);
  203. PIM_OPTION_SET(*hello_options, PIM_OPTION_MASK_HOLDTIME);
  204. *hello_option_holdtime = PIM_TLV_GET_HOLDTIME(tlv_curr);
  205. return 0;
  206. }
  207. int pim_tlv_parse_lan_prune_delay(const char *ifname, struct in_addr src_addr,
  208. pim_hello_options *hello_options,
  209. uint16_t *hello_option_propagation_delay,
  210. uint16_t *hello_option_override_interval,
  211. uint16_t option_len,
  212. const uint8_t *tlv_curr)
  213. {
  214. if (check_tlv_length(__PRETTY_FUNCTION__, "lan_prune_delay",
  215. ifname, src_addr,
  216. sizeof(uint32_t), option_len)) {
  217. return -1;
  218. }
  219. check_tlv_redefinition_uint16(__PRETTY_FUNCTION__, "propagation_delay",
  220. ifname, src_addr,
  221. *hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY,
  222. PIM_TLV_GET_PROPAGATION_DELAY(tlv_curr),
  223. *hello_option_propagation_delay);
  224. PIM_OPTION_SET(*hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY);
  225. *hello_option_propagation_delay = PIM_TLV_GET_PROPAGATION_DELAY(tlv_curr);
  226. if (PIM_TLV_GET_CAN_DISABLE_JOIN_SUPPRESSION(tlv_curr)) {
  227. PIM_OPTION_SET(*hello_options, PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION);
  228. }
  229. else {
  230. PIM_OPTION_UNSET(*hello_options, PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION);
  231. }
  232. ++tlv_curr;
  233. ++tlv_curr;
  234. *hello_option_override_interval = PIM_TLV_GET_OVERRIDE_INTERVAL(tlv_curr);
  235. return 0;
  236. }
  237. int pim_tlv_parse_dr_priority(const char *ifname, struct in_addr src_addr,
  238. pim_hello_options *hello_options,
  239. uint32_t *hello_option_dr_priority,
  240. uint16_t option_len,
  241. const uint8_t *tlv_curr)
  242. {
  243. const char *label = "dr_priority";
  244. if (check_tlv_length(__PRETTY_FUNCTION__, label,
  245. ifname, src_addr,
  246. sizeof(uint32_t), option_len)) {
  247. return -1;
  248. }
  249. check_tlv_redefinition_uint32(__PRETTY_FUNCTION__, label,
  250. ifname, src_addr,
  251. *hello_options, PIM_OPTION_MASK_DR_PRIORITY,
  252. PIM_TLV_GET_DR_PRIORITY(tlv_curr),
  253. *hello_option_dr_priority);
  254. PIM_OPTION_SET(*hello_options, PIM_OPTION_MASK_DR_PRIORITY);
  255. *hello_option_dr_priority = PIM_TLV_GET_DR_PRIORITY(tlv_curr);
  256. return 0;
  257. }
  258. int pim_tlv_parse_generation_id(const char *ifname, struct in_addr src_addr,
  259. pim_hello_options *hello_options,
  260. uint32_t *hello_option_generation_id,
  261. uint16_t option_len,
  262. const uint8_t *tlv_curr)
  263. {
  264. const char *label = "generation_id";
  265. if (check_tlv_length(__PRETTY_FUNCTION__, label,
  266. ifname, src_addr,
  267. sizeof(uint32_t), option_len)) {
  268. return -1;
  269. }
  270. check_tlv_redefinition_uint32_hex(__PRETTY_FUNCTION__, label,
  271. ifname, src_addr,
  272. *hello_options, PIM_OPTION_MASK_GENERATION_ID,
  273. PIM_TLV_GET_GENERATION_ID(tlv_curr),
  274. *hello_option_generation_id);
  275. PIM_OPTION_SET(*hello_options, PIM_OPTION_MASK_GENERATION_ID);
  276. *hello_option_generation_id = PIM_TLV_GET_GENERATION_ID(tlv_curr);
  277. return 0;
  278. }
  279. int pim_parse_addr_ucast(const char *ifname, struct in_addr src_addr,
  280. struct prefix *p,
  281. const uint8_t *buf,
  282. int buf_size)
  283. {
  284. const int ucast_encoding_min_len = 3; /* 1 family + 1 type + 1 addr */
  285. const uint8_t *addr;
  286. const uint8_t *pastend;
  287. int family;
  288. int type;
  289. if (buf_size < ucast_encoding_min_len) {
  290. char src_str[100];
  291. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  292. zlog_warn("%s: unicast address encoding overflow: left=%d needed=%d from %s on %s",
  293. __PRETTY_FUNCTION__,
  294. buf_size, ucast_encoding_min_len,
  295. src_str, ifname);
  296. return -1;
  297. }
  298. addr = buf;
  299. pastend = buf + buf_size;
  300. family = *addr++;
  301. type = *addr++;
  302. switch (family) {
  303. case PIM_MSG_ADDRESS_FAMILY_IPV4:
  304. if (type) {
  305. char src_str[100];
  306. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  307. zlog_warn("%s: unknown unicast address encoding type=%d from %s on %s",
  308. __PRETTY_FUNCTION__,
  309. type, src_str, ifname);
  310. return -2;
  311. }
  312. if ((addr + sizeof(struct in_addr)) > pastend) {
  313. char src_str[100];
  314. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  315. zlog_warn("%s: IPv4 unicast address overflow: left=%zd needed=%zu from %s on %s",
  316. __PRETTY_FUNCTION__,
  317. pastend - addr, sizeof(struct in_addr),
  318. src_str, ifname);
  319. return -3;
  320. }
  321. p->family = AF_INET; /* notice: AF_INET != PIM_MSG_ADDRESS_FAMILY_IPV4 */
  322. memcpy(&p->u.prefix4, addr, sizeof(struct in_addr));
  323. addr += sizeof(struct in_addr);
  324. break;
  325. default:
  326. {
  327. char src_str[100];
  328. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  329. zlog_warn("%s: unknown unicast address encoding family=%d from %s on %s",
  330. __PRETTY_FUNCTION__,
  331. family, src_str, ifname);
  332. return -4;
  333. }
  334. }
  335. return addr - buf;
  336. }
  337. int pim_parse_addr_group(const char *ifname, struct in_addr src_addr,
  338. struct prefix *p,
  339. const uint8_t *buf,
  340. int buf_size)
  341. {
  342. const int grp_encoding_min_len = 4; /* 1 family + 1 type + 1 reserved + 1 addr */
  343. const uint8_t *addr;
  344. const uint8_t *pastend;
  345. int family;
  346. int type;
  347. int mask_len;
  348. if (buf_size < grp_encoding_min_len) {
  349. char src_str[100];
  350. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  351. zlog_warn("%s: group address encoding overflow: left=%d needed=%d from %s on %s",
  352. __PRETTY_FUNCTION__,
  353. buf_size, grp_encoding_min_len,
  354. src_str, ifname);
  355. return -1;
  356. }
  357. addr = buf;
  358. pastend = buf + buf_size;
  359. family = *addr++;
  360. type = *addr++;
  361. //++addr;
  362. ++addr; /* skip b_reserved_z fields */
  363. mask_len = *addr++;
  364. switch (family) {
  365. case PIM_MSG_ADDRESS_FAMILY_IPV4:
  366. if (type) {
  367. char src_str[100];
  368. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  369. zlog_warn("%s: unknown group address encoding type=%d from %s on %s",
  370. __PRETTY_FUNCTION__,
  371. type, src_str, ifname);
  372. return -2;
  373. }
  374. if ((addr + sizeof(struct in_addr)) > pastend) {
  375. char src_str[100];
  376. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  377. zlog_warn("%s: IPv4 group address overflow: left=%zd needed=%zu from %s on %s",
  378. __PRETTY_FUNCTION__,
  379. pastend - addr, sizeof(struct in_addr),
  380. src_str, ifname);
  381. return -3;
  382. }
  383. p->family = AF_INET; /* notice: AF_INET != PIM_MSG_ADDRESS_FAMILY_IPV4 */
  384. memcpy(&p->u.prefix4, addr, sizeof(struct in_addr));
  385. p->prefixlen = mask_len;
  386. addr += sizeof(struct in_addr);
  387. break;
  388. default:
  389. {
  390. char src_str[100];
  391. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  392. zlog_warn("%s: unknown group address encoding family=%d from %s on %s",
  393. __PRETTY_FUNCTION__,
  394. family, src_str, ifname);
  395. return -4;
  396. }
  397. }
  398. return addr - buf;
  399. }
  400. int pim_parse_addr_source(const char *ifname,
  401. struct in_addr src_addr,
  402. struct prefix *p,
  403. uint8_t *flags,
  404. const uint8_t *buf,
  405. int buf_size)
  406. {
  407. const int src_encoding_min_len = 4; /* 1 family + 1 type + 1 reserved + 1 addr */
  408. const uint8_t *addr;
  409. const uint8_t *pastend;
  410. int family;
  411. int type;
  412. int mask_len;
  413. if (buf_size < src_encoding_min_len) {
  414. char src_str[100];
  415. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  416. zlog_warn("%s: source address encoding overflow: left=%d needed=%d from %s on %s",
  417. __PRETTY_FUNCTION__,
  418. buf_size, src_encoding_min_len,
  419. src_str, ifname);
  420. return -1;
  421. }
  422. addr = buf;
  423. pastend = buf + buf_size;
  424. family = *addr++;
  425. type = *addr++;
  426. *flags = *addr++;
  427. mask_len = *addr++;
  428. switch (family) {
  429. case PIM_MSG_ADDRESS_FAMILY_IPV4:
  430. if (type) {
  431. char src_str[100];
  432. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  433. zlog_warn("%s: unknown source address encoding type=%d from %s on %s: %02x%02x%02x%02x%02x%02x%02x%02x",
  434. __PRETTY_FUNCTION__,
  435. type, src_str, ifname,
  436. buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
  437. return -2;
  438. }
  439. if ((addr + sizeof(struct in_addr)) > pastend) {
  440. char src_str[100];
  441. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  442. zlog_warn("%s: IPv4 source address overflow: left=%zd needed=%zu from %s on %s",
  443. __PRETTY_FUNCTION__,
  444. pastend - addr, sizeof(struct in_addr),
  445. src_str, ifname);
  446. return -3;
  447. }
  448. p->family = AF_INET; /* notice: AF_INET != PIM_MSG_ADDRESS_FAMILY_IPV4 */
  449. memcpy(&p->u.prefix4, addr, sizeof(struct in_addr));
  450. p->prefixlen = mask_len;
  451. /*
  452. RFC 4601: 4.9.1 Encoded Source and Group Address Formats
  453. Encoded-Source Address
  454. The mask length MUST be equal to the mask length in bits for
  455. the given Address Family and Encoding Type (32 for IPv4 native
  456. and 128 for IPv6 native). A router SHOULD ignore any messages
  457. received with any other mask length.
  458. */
  459. if (p->prefixlen != 32) {
  460. char src_str[100];
  461. pim_inet4_dump("<src?>", p->u.prefix4, src_str, sizeof(src_str));
  462. zlog_warn("%s: IPv4 bad source address mask: %s/%d",
  463. __PRETTY_FUNCTION__, src_str, p->prefixlen);
  464. return -4;
  465. }
  466. addr += sizeof(struct in_addr);
  467. break;
  468. default:
  469. {
  470. char src_str[100];
  471. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  472. zlog_warn("%s: unknown source address encoding family=%d from %s on %s: %02x%02x%02x%02x%02x%02x%02x%02x",
  473. __PRETTY_FUNCTION__,
  474. family, src_str, ifname,
  475. buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
  476. return -5;
  477. }
  478. }
  479. return addr - buf;
  480. }
  481. #define FREE_ADDR_LIST(hello_option_addr_list) \
  482. { \
  483. if (hello_option_addr_list) { \
  484. list_delete(hello_option_addr_list); \
  485. hello_option_addr_list = 0; \
  486. } \
  487. }
  488. int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr,
  489. pim_hello_options *hello_options,
  490. struct list **hello_option_addr_list,
  491. uint16_t option_len,
  492. const uint8_t *tlv_curr)
  493. {
  494. const uint8_t *addr;
  495. const uint8_t *pastend;
  496. zassert(hello_option_addr_list);
  497. /*
  498. Scan addr list
  499. */
  500. addr = tlv_curr;
  501. pastend = tlv_curr + option_len;
  502. while (addr < pastend) {
  503. struct prefix tmp;
  504. int addr_offset;
  505. /*
  506. Parse ucast addr
  507. */
  508. addr_offset = pim_parse_addr_ucast(ifname, src_addr, &tmp,
  509. addr, pastend - addr);
  510. if (addr_offset < 1) {
  511. char src_str[100];
  512. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  513. zlog_warn("%s: pim_parse_addr_ucast() failure: from %s on %s",
  514. __PRETTY_FUNCTION__,
  515. src_str, ifname);
  516. FREE_ADDR_LIST(*hello_option_addr_list);
  517. return -1;
  518. }
  519. addr += addr_offset;
  520. /*
  521. Debug
  522. */
  523. if (PIM_DEBUG_PIM_TRACE) {
  524. switch (tmp.family) {
  525. case AF_INET:
  526. {
  527. char addr_str[100];
  528. char src_str[100];
  529. pim_inet4_dump("<addr?>", tmp.u.prefix4, addr_str, sizeof(addr_str));
  530. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  531. zlog_debug("%s: PIM hello TLV option: list_old_size=%d IPv4 address %s from %s on %s",
  532. __PRETTY_FUNCTION__,
  533. *hello_option_addr_list ?
  534. ((int) listcount(*hello_option_addr_list)) : -1,
  535. addr_str, src_str, ifname);
  536. }
  537. break;
  538. default:
  539. {
  540. char src_str[100];
  541. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  542. zlog_debug("%s: PIM hello TLV option: list_old_size=%d UNKNOWN address family from %s on %s",
  543. __PRETTY_FUNCTION__,
  544. *hello_option_addr_list ?
  545. ((int) listcount(*hello_option_addr_list)) : -1,
  546. src_str, ifname);
  547. }
  548. }
  549. }
  550. /*
  551. Exclude neighbor's primary address if incorrectly included in
  552. the secondary address list
  553. */
  554. if (tmp.family == AF_INET) {
  555. if (tmp.u.prefix4.s_addr == src_addr.s_addr) {
  556. char src_str[100];
  557. pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
  558. zlog_warn("%s: ignoring primary address in secondary list from %s on %s",
  559. __PRETTY_FUNCTION__,
  560. src_str, ifname);
  561. continue;
  562. }
  563. }
  564. /*
  565. Allocate list if needed
  566. */
  567. if (!*hello_option_addr_list) {
  568. *hello_option_addr_list = list_new();
  569. if (!*hello_option_addr_list) {
  570. zlog_err("%s %s: failure: hello_option_addr_list=list_new()",
  571. __FILE__, __PRETTY_FUNCTION__);
  572. return -2;
  573. }
  574. (*hello_option_addr_list)->del = (void (*)(void *)) prefix_free;
  575. }
  576. /*
  577. Attach addr to list
  578. */
  579. {
  580. struct prefix *p;
  581. p = prefix_new();
  582. if (!p) {
  583. zlog_err("%s %s: failure: prefix_new()",
  584. __FILE__, __PRETTY_FUNCTION__);
  585. FREE_ADDR_LIST(*hello_option_addr_list);
  586. return -3;
  587. }
  588. p->family = tmp.family;
  589. p->u.prefix4 = tmp.u.prefix4;
  590. listnode_add(*hello_option_addr_list, p);
  591. }
  592. } /* while (addr < pastend) */
  593. /*
  594. Mark hello option
  595. */
  596. PIM_OPTION_SET(*hello_options, PIM_OPTION_MASK_ADDRESS_LIST);
  597. return 0;
  598. }