bgp_update_print(netdissect_options *ndo,
const u_char *dat, int length)
{
- struct bgp bgp;
+ const struct bgp *bgp_header;
const u_char *p;
int withdrawn_routes_len;
+ char buf[MAXHOSTNAMELEN + 100];
+ int wpfx;
int len;
int i;
+ int add_path;
+ int path_id;
- ND_TCHECK2(dat[0], BGP_SIZE);
+ ND_TCHECK_LEN(dat, BGP_SIZE);
if (length < BGP_SIZE)
goto trunc;
- memcpy(&bgp, dat, BGP_SIZE);
- p = dat + BGP_SIZE; /*XXX*/
+ bgp_header = (const struct bgp *)dat;
+ p = dat + BGP_SIZE;
length -= BGP_SIZE;
/* Unfeasible routes */
- ND_TCHECK2(p[0], 2);
+ ND_TCHECK_2(p);
if (length < 2)
goto trunc;
- withdrawn_routes_len = EXTRACT_16BITS(p);
+ withdrawn_routes_len = EXTRACT_BE_U_2(p);
p += 2;
length -= 2;
- if (withdrawn_routes_len) {
+ if (withdrawn_routes_len > 1) {
- ND_TCHECK2(p[0], withdrawn_routes_len);
+ /*
+ * Without keeping state from the original NLRI message,
+ * it's not possible to tell if this a v4 or v6 route,
+ * so only try to decode it if we're not v6 enabled.
- */
++ */
+ ND_TCHECK_LEN(p, withdrawn_routes_len);
if (length < withdrawn_routes_len)
goto trunc;
- ND_PRINT((ndo, "\n\t Withdrawn routes: %d bytes", withdrawn_routes_len));
- p += withdrawn_routes_len;
- length -= withdrawn_routes_len;
- }
+
+ ND_PRINT((ndo, "\n\t Withdrawn routes:"));
+ add_path = check_add_path(p, withdrawn_routes_len, 32);
+ while(withdrawn_routes_len > 0) {
+ if (add_path) {
+ path_id = EXTRACT_32BITS(p);
+ p += 4;
+ length -= 4;
+ withdrawn_routes_len -= 4;
+ }
+ wpfx = decode_prefix4(ndo, p, withdrawn_routes_len, buf, sizeof(buf));
+ if (wpfx == -1) {
+ ND_PRINT((ndo, "\n\t (illegal prefix length)"));
+ break;
+ } else if (wpfx == -2)
+ goto trunc;
+ else if (wpfx == -3)
+ goto trunc; /* bytes left, but not enough */
+ else {
+ ND_PRINT((ndo, "\n\t %s", buf));
+ if (add_path) {
+ ND_PRINT((ndo, " Path Id: %d", path_id));
+ }
+ p += wpfx;
+ length -= wpfx;
+ withdrawn_routes_len -= wpfx;
+ }
+ }
+ } else {
+ p += withdrawn_routes_len;
+ length -= withdrawn_routes_len;
+ }
- ND_TCHECK2(p[0], 2);
+ ND_TCHECK_2(p);
if (length < 2)
goto trunc;
- len = EXTRACT_16BITS(p);
+ len = EXTRACT_BE_U_2(p);
p += 2;
length -= 2;