bgp_capability_test.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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_open.h"
  8. #include "bgpd/bgp_debug.h"
  9. #define VT100_RESET "\x1b[0m"
  10. #define VT100_RED "\x1b[31m"
  11. #define VT100_GREEN "\x1b[32m"
  12. #define VT100_YELLOW "\x1b[33m"
  13. #define CAPABILITY 0
  14. #define DYNCAP 1
  15. #define OPT_PARAM 2
  16. /* need these to link in libbgp */
  17. struct zebra_privs_t *bgpd_privs = NULL;
  18. struct thread_master *master = NULL;
  19. static int failed = 0;
  20. static int tty = 0;
  21. /* test segments to parse and validate, and use for other tests */
  22. static struct test_segment {
  23. const char *name;
  24. const char *desc;
  25. const u_char data[1024];
  26. int len;
  27. #define SHOULD_PARSE 0
  28. #define SHOULD_ERR -1
  29. int parses; /* whether it should parse or not */
  30. int peek_for; /* what peek_for_as4_capability should say */
  31. /* AFI/SAFI validation */
  32. int validate_afi;
  33. afi_t afi;
  34. safi_t safi;
  35. #define VALID_AFI 1
  36. #define INVALID_AFI 0
  37. int afi_valid;
  38. } test_segments [] =
  39. {
  40. /* 0 */
  41. { "caphdr",
  42. "capability header, and no more",
  43. { CAPABILITY_CODE_REFRESH, 0x0 },
  44. 2, SHOULD_PARSE,
  45. },
  46. /* 1 */
  47. { "nodata",
  48. "header, no data but length says there is",
  49. { 0x1, 0xa },
  50. 2, SHOULD_ERR,
  51. },
  52. /* 2 */
  53. { "padded",
  54. "valid, with padding",
  55. { CAPABILITY_CODE_REFRESH, 0x2, 0x0, 0x0 },
  56. 4, SHOULD_PARSE,
  57. },
  58. /* 3 */
  59. { "minsize",
  60. "violates minsize requirement",
  61. { CAPABILITY_CODE_ORF, 0x2, 0x0, 0x0 },
  62. 4, SHOULD_ERR,
  63. },
  64. { NULL, NULL, {0}, 0, 0},
  65. };
  66. static struct test_segment mp_segments[] =
  67. {
  68. { "MP4",
  69. "MP IP/Uni",
  70. { 0x1, 0x4, 0x0, 0x1, 0x0, 0x1 },
  71. 6, SHOULD_PARSE, 0,
  72. 1, AFI_IP, SAFI_UNICAST, VALID_AFI,
  73. },
  74. { "MPv6",
  75. "MP IPv6/Uni",
  76. { 0x1, 0x4, 0x0, 0x2, 0x0, 0x1 },
  77. 6, SHOULD_PARSE, 0,
  78. 1, AFI_IP6, SAFI_UNICAST, VALID_AFI,
  79. },
  80. /* 5 */
  81. { "MP2",
  82. "MP IP/Multicast",
  83. { CAPABILITY_CODE_MP, 0x4, 0x0, 0x1, 0x0, 0x2 },
  84. 6, SHOULD_PARSE, 0,
  85. 1, AFI_IP, SAFI_MULTICAST, VALID_AFI,
  86. },
  87. /* 6 */
  88. { "MP3",
  89. "MP IP6/VPNv4",
  90. { CAPABILITY_CODE_MP, 0x4, 0x0, 0x2, 0x0, 0x80 },
  91. 6, SHOULD_PARSE, 0, /* parses, but invalid afi,safi */
  92. 1, AFI_IP6, BGP_SAFI_VPNV4, INVALID_AFI,
  93. },
  94. /* 7 */
  95. { "MP5",
  96. "MP IP6/MPLS-VPN",
  97. { CAPABILITY_CODE_MP, 0x4, 0x0, 0x2, 0x0, 0x4 },
  98. 6, SHOULD_PARSE, 0,
  99. 1, AFI_IP6, SAFI_MPLS_VPN, VALID_AFI,
  100. },
  101. /* 8 */
  102. { "MP6",
  103. "MP IP4/VPNv4",
  104. { CAPABILITY_CODE_MP, 0x4, 0x0, 0x1, 0x0, 0x80 },
  105. 6, SHOULD_PARSE, 0,
  106. 1, AFI_IP, BGP_SAFI_VPNV4, VALID_AFI,
  107. },
  108. /* 9 */
  109. { "MP7",
  110. "MP IP4/VPNv6",
  111. { CAPABILITY_CODE_MP, 0x4, 0x0, 0x1, 0x0, 0x81 },
  112. 6, SHOULD_PARSE, 0, /* parses, but invalid afi,safi tuple */
  113. 1, AFI_IP, BGP_SAFI_VPNV6, INVALID_AFI,
  114. },
  115. /* 10 */
  116. { "MP8",
  117. "MP unknown AFI",
  118. { CAPABILITY_CODE_MP, 0x4, 0x0, 0xa, 0x0, 0x81 },
  119. 6, SHOULD_PARSE, 0,
  120. 1, 0xa, 0x81, INVALID_AFI, /* parses, but unknown */
  121. },
  122. /* 11 */
  123. { "MP-short",
  124. "MP IP4/Unicast, length too short (< minimum)",
  125. { CAPABILITY_CODE_MP, 0x2, 0x0, 0x1, 0x0, 0x1 },
  126. 6, SHOULD_ERR,
  127. },
  128. /* 12 */
  129. { "MP-overflow",
  130. "MP IP4/Unicast, length too long",
  131. { CAPABILITY_CODE_MP, 0x6, 0x0, 0x1, 0x0, 0x1 },
  132. 6, SHOULD_ERR, 0,
  133. 1, AFI_IP, SAFI_UNICAST, VALID_AFI,
  134. },
  135. { NULL, NULL, {0}, 0, 0}
  136. };
  137. static struct test_segment misc_segments[] =
  138. {
  139. /* 13 */
  140. { "ORF",
  141. "ORF, simple, single entry, single tuple",
  142. { /* hdr */ CAPABILITY_CODE_ORF, 0x7,
  143. /* mpc */ 0x0, 0x1, 0x0, 0x1,
  144. /* num */ 0x1,
  145. /* tuples */ 0x40, 0x3
  146. },
  147. 9, SHOULD_PARSE,
  148. },
  149. /* 14 */
  150. { "ORF-many",
  151. "ORF, multi entry/tuple",
  152. { /* hdr */ CAPABILITY_CODE_ORF, 0x21,
  153. /* mpc */ 0x0, 0x1, 0x0, 0x1,
  154. /* num */ 0x3,
  155. /* tuples */ 0x40, ORF_MODE_BOTH,
  156. 0x80, ORF_MODE_RECEIVE,
  157. 0x80, ORF_MODE_SEND,
  158. /* mpc */ 0x0, 0x2, 0x0, 0x1,
  159. /* num */ 0x3,
  160. /* tuples */ 0x40, ORF_MODE_BOTH,
  161. 0x80, ORF_MODE_RECEIVE,
  162. 0x80, ORF_MODE_SEND,
  163. /* mpc */ 0x0, 0x2, 0x0, 0x2,
  164. /* num */ 0x3,
  165. /* tuples */ 0x40, ORF_MODE_RECEIVE,
  166. 0x80, ORF_MODE_SEND,
  167. 0x80, ORF_MODE_BOTH,
  168. },
  169. 35, SHOULD_PARSE,
  170. },
  171. /* 15 */
  172. { "ORFlo",
  173. "ORF, multi entry/tuple, hdr length too short",
  174. { /* hdr */ CAPABILITY_CODE_ORF, 0x15,
  175. /* mpc */ 0x0, 0x1, 0x0, 0x1,
  176. /* num */ 0x3,
  177. /* tuples */ 0x40, 0x3,
  178. 0x80, 0x1,
  179. 0x80, 0x2,
  180. /* mpc */ 0x0, 0x1, 0x0, 0x1,
  181. /* num */ 0x3,
  182. /* tuples */ 0x40, 0x3,
  183. 0x80, 0x1,
  184. 0x80, 0x2,
  185. /* mpc */ 0x0, 0x2, 0x0, 0x2,
  186. /* num */ 0x3,
  187. /* tuples */ 0x40, 0x3,
  188. 0x80, 0x1,
  189. 0x80, 0x2,
  190. },
  191. 35, SHOULD_ERR, /* It should error on invalid Route-Refresh.. */
  192. },
  193. /* 16 */
  194. { "ORFlu",
  195. "ORF, multi entry/tuple, length too long",
  196. { /* hdr */ 0x3, 0x22,
  197. /* mpc */ 0x0, 0x1, 0x0, 0x1,
  198. /* num */ 0x3,
  199. /* tuples */ 0x40, 0x3,
  200. 0x80, 0x1,
  201. 0x80, 0x2,
  202. /* mpc */ 0x0, 0x2, 0x0, 0x1,
  203. /* num */ 0x3,
  204. /* tuples */ 0x40, 0x3,
  205. 0x80, 0x1,
  206. 0x80, 0x2,
  207. /* mpc */ 0x0, 0x2, 0x0, 0x2,
  208. /* num */ 0x3,
  209. /* tuples */ 0x40, 0x3,
  210. 0x80, 0x1,
  211. 0x80, 0x2,
  212. },
  213. 35, SHOULD_ERR
  214. },
  215. /* 17 */
  216. { "ORFnu",
  217. "ORF, multi entry/tuple, entry number too long",
  218. { /* hdr */ 0x3, 0x21,
  219. /* mpc */ 0x0, 0x1, 0x0, 0x1,
  220. /* num */ 0x3,
  221. /* tuples */ 0x40, 0x3,
  222. 0x80, 0x1,
  223. 0x80, 0x2,
  224. /* mpc */ 0x0, 0x2, 0x0, 0x1,
  225. /* num */ 0x4,
  226. /* tuples */ 0x40, 0x3,
  227. 0x80, 0x1,
  228. 0x80, 0x2,
  229. /* mpc */ 0x0, 0x2, 0x0, 0x2,
  230. /* num */ 0x3,
  231. /* tuples */ 0x40, 0x3,
  232. 0x80, 0x1,
  233. 0x80, 0x2,
  234. },
  235. 35, SHOULD_PARSE, /* parses, but last few tuples should be gibberish */
  236. },
  237. /* 18 */
  238. { "ORFno",
  239. "ORF, multi entry/tuple, entry number too short",
  240. { /* hdr */ 0x3, 0x21,
  241. /* mpc */ 0x0, 0x1, 0x0, 0x1,
  242. /* num */ 0x3,
  243. /* tuples */ 0x40, 0x3,
  244. 0x80, 0x1,
  245. 0x80, 0x2,
  246. /* mpc */ 0x0, 0x2, 0x0, 0x1,
  247. /* num */ 0x1,
  248. /* tuples */ 0x40, 0x3,
  249. 0x80, 0x1,
  250. 0x80, 0x2,
  251. /* mpc */ 0x0, 0x2, 0x0, 0x2,
  252. /* num */ 0x3,
  253. /* tuples */ 0x40, 0x3,
  254. 0x80, 0x1,
  255. 0x80, 0x2,
  256. },
  257. 35, SHOULD_PARSE, /* Parses, but should get gibberish afi/safis */
  258. },
  259. /* 17 */
  260. { "ORFpad",
  261. "ORF, multi entry/tuple, padded to align",
  262. { /* hdr */ 0x3, 0x22,
  263. /* mpc */ 0x0, 0x1, 0x0, 0x1,
  264. /* num */ 0x3,
  265. /* tuples */ 0x40, 0x3,
  266. 0x80, 0x1,
  267. 0x80, 0x2,
  268. /* mpc */ 0x0, 0x2, 0x0, 0x1,
  269. /* num */ 0x3,
  270. /* tuples */ 0x40, 0x3,
  271. 0x80, 0x1,
  272. 0x80, 0x2,
  273. /* mpc */ 0x0, 0x2, 0x0, 0x2,
  274. /* num */ 0x3,
  275. /* tuples */ 0x40, 0x3,
  276. 0x80, 0x1,
  277. 0x80, 0x2,
  278. 0x00,
  279. },
  280. 36, SHOULD_PARSE,
  281. },
  282. /* 19 */
  283. { "AS4",
  284. "AS4 capability",
  285. { 0x41, 0x4, 0xab, 0xcd, 0xef, 0x12 }, /* AS: 2882400018 */
  286. 6, SHOULD_PARSE, 2882400018,
  287. },
  288. /* 20 */
  289. { "GR",
  290. "GR capability",
  291. { /* hdr */ CAPABILITY_CODE_RESTART, 0xe,
  292. /* R-bit, time */ 0xf1, 0x12,
  293. /* afi */ 0x0, 0x1,
  294. /* safi */ 0x1,
  295. /* flags */ 0xf,
  296. /* afi */ 0x0, 0x2,
  297. /* safi */ 0x1,
  298. /* flags */ 0x0,
  299. /* afi */ 0x0, 0x2,
  300. /* safi */ 0x2,
  301. /* flags */ 0x1,
  302. },
  303. 16, SHOULD_PARSE,
  304. },
  305. /* 21 */
  306. { "GR-short",
  307. "GR capability, but header length too short",
  308. { /* hdr */ 0x40, 0xa,
  309. /* R-bit, time */ 0xf1, 0x12,
  310. /* afi */ 0x0, 0x1,
  311. /* safi */ 0x1,
  312. /* flags */ 0xf,
  313. /* afi */ 0x0, 0x2,
  314. /* safi */ 0x1,
  315. /* flags */ 0x0,
  316. /* afi */ 0x0, 0x2,
  317. /* safi */ 0x2,
  318. /* flags */ 0x1,
  319. },
  320. 16, SHOULD_PARSE,
  321. },
  322. /* 22 */
  323. { "GR-long",
  324. "GR capability, but header length too long",
  325. { /* hdr */ 0x40, 0xf,
  326. /* R-bit, time */ 0xf1, 0x12,
  327. /* afi */ 0x0, 0x1,
  328. /* safi */ 0x1,
  329. /* flags */ 0xf,
  330. /* afi */ 0x0, 0x2,
  331. /* safi */ 0x1,
  332. /* flags */ 0x0,
  333. /* afi */ 0x0, 0x2,
  334. /* safi */ 0x2,
  335. },
  336. 16, SHOULD_ERR,
  337. },
  338. { "GR-trunc",
  339. "GR capability, but truncated",
  340. { /* hdr */ 0x40, 0xf,
  341. /* R-bit, time */ 0xf1, 0x12,
  342. /* afi */ 0x0, 0x1,
  343. /* safi */ 0x1,
  344. /* flags */ 0xf,
  345. /* afi */ 0x0, 0x2,
  346. /* safi */ 0x1,
  347. /* flags */ 0x0,
  348. /* afi */ 0x0, 0x2,
  349. /* safi */ 0x2,
  350. /* flags */ 0x1,
  351. },
  352. 15, SHOULD_ERR,
  353. },
  354. { "GR-empty",
  355. "GR capability, but empty.",
  356. { /* hdr */ 0x40, 0x0,
  357. },
  358. 2, SHOULD_ERR,
  359. },
  360. { "MP-empty",
  361. "MP capability, but empty.",
  362. { /* hdr */ 0x1, 0x0,
  363. },
  364. 2, SHOULD_ERR,
  365. },
  366. { "ORF-empty",
  367. "ORF capability, but empty.",
  368. { /* hdr */ 0x3, 0x0,
  369. },
  370. 2, SHOULD_ERR,
  371. },
  372. { "AS4-empty",
  373. "AS4 capability, but empty.",
  374. { /* hdr */ 0x41, 0x0,
  375. },
  376. 2, SHOULD_ERR,
  377. },
  378. { "dyn-empty",
  379. "Dynamic capability, but empty.",
  380. { /* hdr */ 0x42, 0x0,
  381. },
  382. 2, SHOULD_PARSE,
  383. },
  384. { "dyn-old",
  385. "Dynamic capability (deprecated version)",
  386. { CAPABILITY_CODE_DYNAMIC, 0x0 },
  387. 2, SHOULD_PARSE,
  388. },
  389. { NULL, NULL, {0}, 0, 0}
  390. };
  391. /* DYNAMIC message */
  392. struct test_segment dynamic_cap_msgs[] =
  393. {
  394. { "DynCap",
  395. "Dynamic Capability Message, IP/Multicast",
  396. { 0x0, 0x1, 0x4, 0x0, 0x1, 0x0, 0x2 },
  397. 7, SHOULD_PARSE, /* horrible alignment, just as with ORF */
  398. },
  399. { "DynCapLong",
  400. "Dynamic Capability Message, IP/Multicast, truncated",
  401. { 0x0, 0x1, 0x4, 0x0, 0x1, 0x0, 0x2 },
  402. 5, SHOULD_ERR,
  403. },
  404. { "DynCapPadded",
  405. "Dynamic Capability Message, IP/Multicast, padded",
  406. { 0x0, 0x1, 0x4, 0x0, 0x1, 0x0, 0x2, 0x0 },
  407. 8, SHOULD_ERR, /* No way to tell padding from data.. */
  408. },
  409. { "DynCapMPCpadded",
  410. "Dynamic Capability Message, IP/Multicast, cap data padded",
  411. { 0x0, 0x1, 0x5, 0x0, 0x1, 0x0, 0x2, 0x0 },
  412. 8, SHOULD_PARSE, /* You can though add padding to the capability data */
  413. },
  414. { "DynCapMPCoverflow",
  415. "Dynamic Capability Message, IP/Multicast, cap data != length",
  416. { 0x0, 0x1, 0x3, 0x0, 0x1, 0x0, 0x2, 0x0 },
  417. 8, SHOULD_ERR,
  418. },
  419. { NULL, NULL, {0}, 0, 0}
  420. };
  421. /* Entire Optional-Parameters block */
  422. struct test_segment opt_params[] =
  423. {
  424. { "Cap-singlets",
  425. "One capability per Optional-Param",
  426. { 0x02, 0x06, 0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/Uni */
  427. 0x02, 0x06, 0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/Uni */
  428. 0x02, 0x02, 0x80, 0x00, /* RR (old) */
  429. 0x02, 0x02, 0x02, 0x00, /* RR */
  430. },
  431. 24, SHOULD_PARSE,
  432. },
  433. { "Cap-series",
  434. "Series of capability, one Optional-Param",
  435. { 0x02, 0x10,
  436. 0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/Uni */
  437. 0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/Uni */
  438. 0x80, 0x00, /* RR (old) */
  439. 0x02, 0x00, /* RR */
  440. },
  441. 18, SHOULD_PARSE,
  442. },
  443. { "AS4more",
  444. "AS4 capability after other caps (singlets)",
  445. { 0x02, 0x06, 0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/Uni */
  446. 0x02, 0x06, 0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/Uni */
  447. 0x02, 0x02, 0x80, 0x00, /* RR (old) */
  448. 0x02, 0x02, 0x02, 0x00, /* RR */
  449. 0x02, 0x06, 0x41, 0x04, 0x00, 0x03, 0x00, 0x06 /* AS4: 1996614 */
  450. },
  451. 32, SHOULD_PARSE, 196614,
  452. },
  453. { "AS4series",
  454. "AS4 capability, in series of capabilities",
  455. { 0x02, 0x16,
  456. 0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/Uni */
  457. 0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/Uni */
  458. 0x80, 0x00, /* RR (old) */
  459. 0x02, 0x00, /* RR */
  460. 0x41, 0x04, 0x00, 0x03, 0x00, 0x06 /* AS4: 1996614 */
  461. },
  462. 24, SHOULD_PARSE, 196614,
  463. },
  464. { "AS4real",
  465. "AS4 capability, in series of capabilities",
  466. {
  467. 0x02, 0x06, 0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/uni */
  468. 0x02, 0x06, 0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/uni */
  469. 0x02, 0x02, 0x80, 0x00, /* RR old */
  470. 0x02, 0x02, 0x02, 0x00, /* RR */
  471. 0x02, 0x06, 0x41, 0x04, 0x00, 0x03, 0x00, 0x06, /* AS4 */
  472. },
  473. 32, SHOULD_PARSE, 196614,
  474. },
  475. { "AS4real2",
  476. "AS4 capability, in series of capabilities",
  477. {
  478. 0x02, 0x06, 0x01, 0x04, 0x00, 0x01, 0x00, 0x01,
  479. 0x02, 0x06, 0x01, 0x04, 0x00, 0x02, 0x00, 0x01,
  480. 0x02, 0x02, 0x80, 0x00,
  481. 0x02, 0x02, 0x02, 0x00,
  482. 0x02, 0x06, 0x41, 0x04, 0x00, 0x00, 0xfc, 0x03,
  483. 0x02, 0x09, 0x82, 0x07, 0x00, 0x01, 0x00, 0x01, 0x01, 0x80, 0x03,
  484. 0x02, 0x09, 0x03, 0x07, 0x00, 0x01, 0x00, 0x01, 0x01, 0x40, 0x03,
  485. 0x02, 0x02, 0x42, 0x00,
  486. },
  487. 58, SHOULD_PARSE, 64515,
  488. },
  489. { NULL, NULL, {0}, 0, 0}
  490. };
  491. /* basic parsing test */
  492. static void
  493. parse_test (struct peer *peer, struct test_segment *t, int type)
  494. {
  495. int ret;
  496. int capability = 0;
  497. as_t as4 = 0;
  498. int oldfailed = failed;
  499. int len = t->len;
  500. #define RANDOM_FUZZ 35
  501. stream_reset (peer->ibuf);
  502. stream_put (peer->ibuf, NULL, RANDOM_FUZZ);
  503. stream_set_getp (peer->ibuf, RANDOM_FUZZ);
  504. switch (type)
  505. {
  506. case CAPABILITY:
  507. stream_putc (peer->ibuf, BGP_OPEN_OPT_CAP);
  508. stream_putc (peer->ibuf, t->len);
  509. break;
  510. case DYNCAP:
  511. /* for (i = 0; i < BGP_MARKER_SIZE; i++)
  512. stream_putc (peer->, 0xff);
  513. stream_putw (s, 0);
  514. stream_putc (s, BGP_MSG_CAPABILITY);*/
  515. break;
  516. }
  517. stream_write (peer->ibuf, t->data, t->len);
  518. printf ("%s: %s\n", t->name, t->desc);
  519. switch (type)
  520. {
  521. case CAPABILITY:
  522. len += 2; /* to cover the OPT-Param header */
  523. case OPT_PARAM:
  524. printf ("len: %u\n", len);
  525. /* peek_for_as4 wants getp at capibility*/
  526. as4 = peek_for_as4_capability (peer, len);
  527. printf ("peek_for_as4: as4 is %u\n", as4);
  528. /* and it should leave getp as it found it */
  529. assert (stream_get_getp (peer->ibuf) == RANDOM_FUZZ);
  530. ret = bgp_open_option_parse (peer, len, &capability);
  531. break;
  532. case DYNCAP:
  533. ret = bgp_capability_receive (peer, t->len);
  534. break;
  535. default:
  536. printf ("unknown type %u\n", type);
  537. exit(1);
  538. }
  539. if (!ret && t->validate_afi)
  540. {
  541. safi_t safi = t->safi;
  542. if (bgp_afi_safi_valid_indices (t->afi, &safi) != t->afi_valid)
  543. failed++;
  544. printf ("MP: %u/%u (%u): recv %u, nego %u\n",
  545. t->afi, t->safi, safi,
  546. peer->afc_recv[t->afi][safi],
  547. peer->afc_nego[t->afi][safi]);
  548. if (t->afi_valid == VALID_AFI)
  549. {
  550. if (!peer->afc_recv[t->afi][safi])
  551. failed++;
  552. if (!peer->afc_nego[t->afi][safi])
  553. failed++;
  554. }
  555. }
  556. if (as4 != t->peek_for)
  557. {
  558. printf ("as4 %u != %u\n", as4, t->peek_for);
  559. failed++;
  560. }
  561. printf ("parsed?: %s\n", ret ? "no" : "yes");
  562. if (ret != t->parses)
  563. failed++;
  564. if (tty)
  565. printf ("%s", (failed > oldfailed) ? VT100_RED "failed!" VT100_RESET
  566. : VT100_GREEN "OK" VT100_RESET);
  567. else
  568. printf ("%s", (failed > oldfailed) ? "failed!" : "OK" );
  569. if (failed)
  570. printf (" (%u)", failed);
  571. printf ("\n\n");
  572. }
  573. static struct bgp *bgp;
  574. static as_t asn = 100;
  575. int
  576. main (void)
  577. {
  578. struct peer *peer;
  579. int i, j;
  580. conf_bgp_debug_fsm = -1UL;
  581. conf_bgp_debug_events = -1UL;
  582. conf_bgp_debug_packet = -1UL;
  583. conf_bgp_debug_normal = -1UL;
  584. conf_bgp_debug_as4 = -1UL;
  585. term_bgp_debug_fsm = -1UL;
  586. term_bgp_debug_events = -1UL;
  587. term_bgp_debug_packet = -1UL;
  588. term_bgp_debug_normal = -1UL;
  589. term_bgp_debug_as4 = -1UL;
  590. master = thread_master_create ();
  591. bgp_master_init ();
  592. if (fileno (stdout) >= 0)
  593. tty = isatty (fileno (stdout));
  594. if (bgp_get (&bgp, &asn, NULL))
  595. return -1;
  596. peer = peer_create_accept (bgp);
  597. peer->host = "foo";
  598. for (i = AFI_IP; i < AFI_MAX; i++)
  599. for (j = SAFI_UNICAST; j < SAFI_MAX; j++)
  600. {
  601. peer->afc[i][j] = 1;
  602. peer->afc_adv[i][j] = 1;
  603. }
  604. i = 0;
  605. while (mp_segments[i].name)
  606. parse_test (peer, &mp_segments[i++], CAPABILITY);
  607. /* These tests assume mp_segments tests set at least
  608. * one of the afc_nego's
  609. */
  610. i = 0;
  611. while (test_segments[i].name)
  612. parse_test (peer, &test_segments[i++], CAPABILITY);
  613. i = 0;
  614. while (misc_segments[i].name)
  615. parse_test (peer, &misc_segments[i++], CAPABILITY);
  616. i = 0;
  617. while (opt_params[i].name)
  618. parse_test (peer, &opt_params[i++], OPT_PARAM);
  619. SET_FLAG (peer->cap, PEER_CAP_DYNAMIC_ADV);
  620. peer->status = Established;
  621. i = 0;
  622. while (dynamic_cap_msgs[i].name)
  623. parse_test (peer, &dynamic_cap_msgs[i++], DYNCAP);
  624. printf ("failures: %d\n", failed);
  625. return failed;
  626. }