bgp_mp_attr_test.c 18 KB

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