bgp_mp_attr_test.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. #include <zebra.h>
  2. #include "vty.h"
  3. #include "stream.h"
  4. #include "privs.h"
  5. #include "memory.h"
  6. #include "bgpd/bgpd.h"
  7. #include "bgpd/bgp_attr.h"
  8. #include "bgpd/bgp_open.h"
  9. #include "bgpd/bgp_debug.h"
  10. #define VT100_RESET "\x1b[0m"
  11. #define VT100_RED "\x1b[31m"
  12. #define VT100_GREEN "\x1b[32m"
  13. #define VT100_YELLOW "\x1b[33m"
  14. #define CAPABILITY 0
  15. #define DYNCAP 1
  16. #define OPT_PARAM 2
  17. /* need these to link in libbgp */
  18. struct zebra_privs_t *bgpd_privs = NULL;
  19. struct thread_master *master = NULL;
  20. static int failed = 0;
  21. static int tty = 0;
  22. /* test segments to parse and validate, and use for other tests */
  23. static struct test_segment {
  24. const char *name;
  25. const char *desc;
  26. const u_char data[1024];
  27. int len;
  28. #define SHOULD_PARSE 0
  29. #define SHOULD_ERR -1
  30. int parses; /* whether it should parse or not */
  31. /* AFI/SAFI validation */
  32. afi_t afi;
  33. safi_t safi;
  34. #define VALID_AFI 1
  35. #define INVALID_AFI 0
  36. int afi_valid;
  37. } mp_reach_segments [] =
  38. {
  39. { "IPv6",
  40. "IPV6 MP Reach, global nexthop, 1 NLRI",
  41. {
  42. /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
  43. /* nexthop bytes */ 16,
  44. /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2,
  45. 0xaa, 0xbb, 0xcc, 0xdd,
  46. 0x3, 0x4, 0x5, 0x6,
  47. 0xa1, 0xa2, 0xa3, 0xa4,
  48. /* SNPA (defunct, MBZ) */ 0x0,
  49. /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
  50. },
  51. (4 + 16 + 1 + 5),
  52. SHOULD_PARSE,
  53. AFI_IP6, SAFI_UNICAST, VALID_AFI,
  54. },
  55. { "IPv6-2",
  56. "IPV6 MP Reach, global nexthop, 2 NLRIs",
  57. {
  58. /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
  59. /* nexthop bytes */ 16,
  60. /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* ffee:102:... */
  61. 0xaa, 0xbb, 0xcc, 0xdd,
  62. 0x3, 0x4, 0x5, 0x6,
  63. 0xa1, 0xa2, 0xa3, 0xa4,
  64. /* SNPA (defunct, MBZ) */ 0x0,
  65. /* NLRI tuples */ 32,
  66. 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
  67. 64,
  68. 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
  69. 0x0, 0x2, 0x0, 0x3,
  70. },
  71. (4 + 16 + 1 + 5 + 9),
  72. SHOULD_PARSE,
  73. AFI_IP6, SAFI_UNICAST, VALID_AFI,
  74. },
  75. { "IPv6-default",
  76. "IPV6 MP Reach, global nexthop, 2 NLRIs + default",
  77. {
  78. /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
  79. /* nexthop bytes */ 16,
  80. /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2,
  81. 0xaa, 0xbb, 0xcc, 0xdd,
  82. 0x3, 0x4, 0x5, 0x6,
  83. 0xa1, 0xa2, 0xa3, 0xa4,
  84. /* SNPA (defunct, MBZ) */ 0x0,
  85. /* NLRI tuples */ 32,
  86. 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
  87. 64,
  88. 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
  89. 0x0, 0x2, 0x0, 0x3,
  90. 0x0, /* ::/0 */
  91. },
  92. (4 + 16 + 1 + 5 + 9 + 1),
  93. SHOULD_PARSE,
  94. AFI_IP6, SAFI_UNICAST, VALID_AFI,
  95. },
  96. { "IPv6-lnh",
  97. "IPV6 MP Reach, global+local nexthops, 2 NLRIs + default",
  98. {
  99. /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
  100. /* nexthop bytes */ 32,
  101. /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
  102. 0xaa, 0xbb, 0xcc, 0xdd,
  103. 0x3, 0x4, 0x5, 0x6,
  104. 0xa1, 0xa2, 0xa3, 0xa4,
  105. /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
  106. 0x0, 0x0, 0x0, 0x0,
  107. 0x2, 0x10, 0x2, 0xff,
  108. 0x1, 0x2, 0x3, 0x4,
  109. /* SNPA (defunct, MBZ) */ 0x0,
  110. /* NLRI tuples */ 32,
  111. 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
  112. 64,
  113. 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
  114. 0x0, 0x2, 0x0, 0x3,
  115. 0x0, /* ::/0 */
  116. },
  117. (4 + 32 + 1 + 5 + 9 + 1),
  118. SHOULD_PARSE,
  119. AFI_IP6, SAFI_UNICAST, VALID_AFI,
  120. },
  121. { "IPv6-nhlen",
  122. "IPV6 MP Reach, inappropriate nexthop length",
  123. {
  124. /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
  125. /* nexthop bytes */ 4,
  126. /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
  127. 0xaa, 0xbb, 0xcc, 0xdd,
  128. 0x3, 0x4, 0x5, 0x6,
  129. 0xa1, 0xa2, 0xa3, 0xa4,
  130. /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
  131. 0x0, 0x0, 0x0, 0x0,
  132. 0x2, 0x10, 0x2, 0xff,
  133. 0x1, 0x2, 0x3, 0x4,
  134. /* SNPA (defunct, MBZ) */ 0x0,
  135. /* NLRI tuples */ 32,
  136. 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
  137. 64,
  138. 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
  139. 0x0, 0x2, 0x0, 0x3,
  140. 0x0, /* ::/0 */
  141. },
  142. (4 + 32 + 1 + 5 + 9 + 1),
  143. SHOULD_ERR,
  144. AFI_IP6, SAFI_UNICAST, VALID_AFI,
  145. },
  146. { "IPv6-nhlen2",
  147. "IPV6 MP Reach, invalid nexthop length",
  148. {
  149. /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
  150. /* nexthop bytes */ 5,
  151. /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
  152. 0xaa, 0xbb, 0xcc, 0xdd,
  153. 0x3, 0x4, 0x5, 0x6,
  154. 0xa1, 0xa2, 0xa3, 0xa4,
  155. /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
  156. 0x0, 0x0, 0x0, 0x0,
  157. 0x2, 0x10, 0x2, 0xff,
  158. 0x1, 0x2, 0x3, 0x4,
  159. /* SNPA (defunct, MBZ) */ 0x0,
  160. /* NLRI tuples */ 32,
  161. 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
  162. 64,
  163. 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
  164. 0x0, 0x2, 0x0, 0x3,
  165. 0x0, /* ::/0 */
  166. },
  167. (4 + 32 + 1 + 5 + 9 + 1),
  168. SHOULD_ERR,
  169. AFI_IP6, SAFI_UNICAST, VALID_AFI,
  170. },
  171. { "IPv6-nhlen3",
  172. "IPV6 MP Reach, nexthop length overflow",
  173. {
  174. /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
  175. /* nexthop bytes */ 32,
  176. /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
  177. 0xaa, 0xbb, 0xcc, 0xdd,
  178. 0x3, 0x4, 0x5, 0x6,
  179. 0xa1, 0xa2, 0xa3, 0xa4,
  180. },
  181. (4 + 16),
  182. SHOULD_ERR,
  183. AFI_IP6, SAFI_UNICAST, VALID_AFI,
  184. },
  185. { "IPv6-nhlen4",
  186. "IPV6 MP Reach, nexthop length short",
  187. {
  188. /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
  189. /* nexthop bytes */ 16,
  190. /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
  191. 0xaa, 0xbb, 0xcc, 0xdd,
  192. 0x3, 0x4, 0x5, 0x6,
  193. 0xa1, 0xa2, 0xa3, 0xa4,
  194. /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
  195. 0x0, 0x0, 0x0, 0x0,
  196. 0x2, 0x10, 0x2, 0xff,
  197. 0x1, 0x2, 0x3, 0x4,
  198. /* SNPA (defunct, MBZ) */ 0x0,
  199. /* NLRI tuples */ 32,
  200. 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
  201. 64,
  202. 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
  203. 0x0, 0x2, 0x0, 0x3,
  204. 0x0, /* ::/0 */
  205. },
  206. (4 + 32 + 1 + 5 + 9 + 1),
  207. SHOULD_ERR,
  208. AFI_IP6, SAFI_UNICAST, VALID_AFI,
  209. },
  210. { "IPv6-nlri",
  211. "IPV6 MP Reach, NLRI bitlen overflow",
  212. {
  213. /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
  214. /* nexthop bytes */ 32,
  215. /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
  216. 0xaa, 0xbb, 0xcc, 0xdd,
  217. 0x3, 0x4, 0x5, 0x6,
  218. 0xa1, 0xa2, 0xa3, 0xa4,
  219. /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
  220. 0x0, 0x0, 0x0, 0x0,
  221. 0x2, 0x10, 0x2, 0xff,
  222. 0x1, 0x2, 0x3, 0x4,
  223. /* SNPA (defunct, MBZ) */ 0x0,
  224. /* NLRI tuples */ 120,
  225. 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
  226. 64,
  227. 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
  228. 0x0, 0x2, 0x0, 0x3,
  229. 0, /* ::/0 */
  230. },
  231. (4 + 32 + 1 + 5 + 9 + 1),
  232. SHOULD_ERR,
  233. AFI_IP6, SAFI_UNICAST, VALID_AFI,
  234. },
  235. { "IPv4",
  236. "IPv4 MP Reach, 2 NLRIs + default",
  237. {
  238. /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
  239. /* nexthop bytes */ 4,
  240. /* Nexthop */ 192, 168, 0, 1,
  241. /* SNPA (defunct, MBZ) */ 0x0,
  242. /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
  243. 17, 10, 2, 3, /* 10.2.3/17 */
  244. 0, /* 0/0 */
  245. },
  246. (4 + 4 + 1 + 3 + 4 + 1),
  247. SHOULD_PARSE,
  248. AFI_IP, SAFI_UNICAST, VALID_AFI,
  249. },
  250. { "IPv4-nhlen",
  251. "IPv4 MP Reach, nexthop lenth overflow",
  252. {
  253. /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
  254. /* nexthop bytes */ 32,
  255. /* Nexthop */ 192, 168, 0, 1,
  256. /* SNPA (defunct, MBZ) */ 0x0,
  257. /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
  258. 17, 10, 2, 3, /* 10.2.3/17 */
  259. 0, /* 0/0 */
  260. },
  261. (4 + 4 + 1 + 3 + 4 + 1),
  262. SHOULD_ERR,
  263. AFI_IP, SAFI_UNICAST, VALID_AFI,
  264. },
  265. { "IPv4-nlrilen",
  266. "IPv4 MP Reach, nlri lenth overflow",
  267. {
  268. /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
  269. /* nexthop bytes */ 4,
  270. /* Nexthop */ 192, 168, 0, 1,
  271. /* SNPA (defunct, MBZ) */ 0x0,
  272. /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
  273. 30, 10,
  274. 0, /* 0/0 */
  275. },
  276. (4 + 4 + 1 + 3 + 2 + 1),
  277. SHOULD_ERR,
  278. AFI_IP, SAFI_UNICAST, VALID_AFI,
  279. },
  280. { "IPv4-MLVPN",
  281. "IPv4/MPLS-labeled VPN MP Reach, RD, Nexthop, 3 NLRIs",
  282. {
  283. /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
  284. /* nexthop bytes */ 12,
  285. /* RD */ 0, 0, 1, 2,
  286. 0, 0xff, 3, 4,
  287. /* Nexthop */ 192, 168, 0, 1,
  288. /* SNPA (defunct, MBZ) */ 0x0,
  289. /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
  290. 17, 10, 2, 3, /* 10.2.3/17 */
  291. 0, /* 0/0 */
  292. },
  293. (4 + 12 + 1 + 3 + 4 + 1),
  294. SHOULD_PARSE,
  295. AFI_IP, SAFI_UNICAST, VALID_AFI,
  296. },
  297. /* From bug #385 */
  298. { "IPv6-bug",
  299. "IPv6, global nexthop, 1 default NLRI",
  300. {
  301. /* AFI / SAFI */ 0x0, 0x2, 0x1,
  302. /* nexthop bytes */ 0x20,
  303. /* Nexthop (global) */ 0x20, 0x01, 0x04, 0x70,
  304. 0x00, 0x01, 0x00, 0x06,
  305. 0x00, 0x00, 0x00, 0x00,
  306. 0x00, 0x00, 0x00, 0x01,
  307. /* Nexthop (local) */ 0xfe, 0x80, 0x00, 0x00,
  308. 0x00, 0x00, 0x00, 0x00,
  309. 0x02, 0x0c, 0xdb, 0xff,
  310. 0xfe, 0xfe, 0xeb, 0x00,
  311. /* SNPA (defunct, MBZ) */ 0,
  312. /* NLRI tuples */ /* Should have 0 here for ::/0, but dont */
  313. },
  314. 37,
  315. SHOULD_ERR,
  316. AFI_IP6, SAFI_UNICAST, VALID_AFI,
  317. },
  318. { NULL, NULL, {0}, 0, 0}
  319. };
  320. /* MP_UNREACH_NLRI tests */
  321. static struct test_segment mp_unreach_segments [] =
  322. {
  323. { "IPv6-unreach",
  324. "IPV6 MP Unreach, 1 NLRI",
  325. {
  326. /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
  327. /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
  328. },
  329. (3 + 5),
  330. SHOULD_PARSE,
  331. AFI_IP6, SAFI_UNICAST, VALID_AFI,
  332. },
  333. { "IPv6-unreach2",
  334. "IPV6 MP Unreach, 2 NLRIs",
  335. {
  336. /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
  337. /* NLRI tuples */ 32,
  338. 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
  339. 64,
  340. 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
  341. 0x0, 0x2, 0x0, 0x3,
  342. },
  343. (3 + 5 + 9),
  344. SHOULD_PARSE,
  345. AFI_IP6, SAFI_UNICAST, VALID_AFI,
  346. },
  347. { "IPv6-unreach-default",
  348. "IPV6 MP Unreach, 2 NLRIs + default",
  349. {
  350. /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
  351. /* NLRI tuples */ 32,
  352. 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
  353. 64,
  354. 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
  355. 0x0, 0x2, 0x0, 0x3,
  356. 0x0, /* ::/0 */
  357. },
  358. (3 + 5 + 9 + 1),
  359. SHOULD_PARSE,
  360. AFI_IP6, SAFI_UNICAST, VALID_AFI,
  361. },
  362. { "IPv6-unreach-nlri",
  363. "IPV6 MP Unreach, NLRI bitlen overflow",
  364. {
  365. /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
  366. /* NLRI tuples */ 120,
  367. 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
  368. 64,
  369. 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
  370. 0x0, 0x2, 0x0, 0x3,
  371. 0, /* ::/0 */
  372. },
  373. (3 + 5 + 9 + 1),
  374. SHOULD_ERR,
  375. AFI_IP6, SAFI_UNICAST, VALID_AFI,
  376. },
  377. { "IPv4-unreach",
  378. "IPv4 MP Unreach, 2 NLRIs + default",
  379. {
  380. /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
  381. /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
  382. 17, 10, 2, 3, /* 10.2.3/17 */
  383. 0, /* 0/0 */
  384. },
  385. (3 + 3 + 4 + 1),
  386. SHOULD_PARSE,
  387. AFI_IP, SAFI_UNICAST, VALID_AFI,
  388. },
  389. { "IPv4-unreach-nlrilen",
  390. "IPv4 MP Unreach, nlri length overflow",
  391. {
  392. /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
  393. /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
  394. 30, 10,
  395. 0, /* 0/0 */
  396. },
  397. (3 + 3 + 2 + 1),
  398. SHOULD_ERR,
  399. AFI_IP, SAFI_UNICAST, VALID_AFI,
  400. },
  401. { "IPv4-unreach-MLVPN",
  402. "IPv4/MPLS-labeled VPN MP Unreach, RD, 3 NLRIs",
  403. {
  404. /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
  405. /* nexthop bytes */ 12,
  406. /* RD */ 0, 0, 1, 2,
  407. 0, 0xff, 3, 4,
  408. /* Nexthop */ 192, 168, 0, 1,
  409. /* SNPA (defunct, MBZ) */ 0x0,
  410. /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
  411. 17, 10, 2, 3, /* 10.2.3/17 */
  412. 0, /* 0/0 */
  413. },
  414. (3 + 3 + 4 + 1),
  415. SHOULD_PARSE,
  416. AFI_IP, SAFI_UNICAST, VALID_AFI,
  417. },
  418. { NULL, NULL, {0}, 0, 0}
  419. };
  420. /* basic parsing test */
  421. static void
  422. parse_test (struct peer *peer, struct test_segment *t, int type)
  423. {
  424. int ret;
  425. int oldfailed = failed;
  426. struct attr attr = { };
  427. struct bgp_nlri nlri = { };
  428. struct bgp_attr_parser_args attr_args = {
  429. .peer = peer,
  430. .length = t->len,
  431. .total = 1,
  432. .attr = &attr,
  433. .type = BGP_ATTR_MP_REACH_NLRI,
  434. .flags = BGP_ATTR_FLAG_OPTIONAL,
  435. .startp = BGP_INPUT_PNT (peer),
  436. };
  437. #define RANDOM_FUZZ 35
  438. stream_reset (peer->ibuf);
  439. stream_put (peer->ibuf, NULL, RANDOM_FUZZ);
  440. stream_set_getp (peer->ibuf, RANDOM_FUZZ);
  441. stream_write (peer->ibuf, t->data, t->len);
  442. printf ("%s: %s\n", t->name, t->desc);
  443. if (type == BGP_ATTR_MP_REACH_NLRI)
  444. ret = bgp_mp_reach_parse (&attr_args, &nlri);
  445. else
  446. ret = bgp_mp_unreach_parse (&attr_args, &nlri);
  447. if (!ret)
  448. {
  449. safi_t safi = t->safi;
  450. if (bgp_afi_safi_valid_indices (t->afi, &safi) != t->afi_valid)
  451. failed++;
  452. printf ("MP: %u/%u (%u): recv %u, nego %u\n",
  453. t->afi, t->safi, safi,
  454. peer->afc_recv[t->afi][safi],
  455. peer->afc_nego[t->afi][safi]);
  456. }
  457. printf ("parsed?: %s\n", ret ? "no" : "yes");
  458. if (ret != t->parses)
  459. failed++;
  460. if (tty)
  461. printf ("%s", (failed > oldfailed) ? VT100_RED "failed!" VT100_RESET
  462. : VT100_GREEN "OK" VT100_RESET);
  463. else
  464. printf ("%s", (failed > oldfailed) ? "failed!" : "OK" );
  465. if (failed)
  466. printf (" (%u)", failed);
  467. printf ("\n\n");
  468. }
  469. static struct bgp *bgp;
  470. static as_t asn = 100;
  471. int
  472. main (void)
  473. {
  474. struct peer *peer;
  475. int i, j;
  476. conf_bgp_debug_fsm = -1UL;
  477. conf_bgp_debug_events = -1UL;
  478. conf_bgp_debug_packet = -1UL;
  479. conf_bgp_debug_normal = -1UL;
  480. conf_bgp_debug_as4 = -1UL;
  481. term_bgp_debug_fsm = -1UL;
  482. term_bgp_debug_events = -1UL;
  483. term_bgp_debug_packet = -1UL;
  484. term_bgp_debug_normal = -1UL;
  485. term_bgp_debug_as4 = -1UL;
  486. master = thread_master_create ();
  487. bgp_master_init ();
  488. bgp_option_set (BGP_OPT_NO_LISTEN);
  489. if (fileno (stdout) >= 0)
  490. tty = isatty (fileno (stdout));
  491. if (bgp_get (&bgp, &asn, NULL))
  492. return -1;
  493. peer = peer_create_accept (bgp);
  494. peer->host = "foo";
  495. for (i = AFI_IP; i < AFI_MAX; i++)
  496. for (j = SAFI_UNICAST; j < SAFI_MAX; j++)
  497. {
  498. peer->afc[i][j] = 1;
  499. peer->afc_adv[i][j] = 1;
  500. }
  501. i = 0;
  502. while (mp_reach_segments[i].name)
  503. parse_test (peer, &mp_reach_segments[i++], BGP_ATTR_MP_REACH_NLRI);
  504. i = 0;
  505. while (mp_unreach_segments[i].name)
  506. parse_test (peer, &mp_unreach_segments[i++], BGP_ATTR_MP_UNREACH_NLRI);
  507. printf ("failures: %d\n", failed);
  508. return failed;
  509. }