bgp_mp_attr_test.c 18 KB

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