Skip to content

Commit 75289ca

Browse files
committed
IPv6: Discard NA packets with a zero length option
As per RFC 4861 4.6. Fixes #415.
1 parent 0f303ab commit 75289ca

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/ipv6nd.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,12 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx,
974974
bool new_ia;
975975
#endif
976976

977+
#define FREE_RAP(rap) \
978+
if (new_rap) \
979+
ipv6nd_removefreedrop_ra(rap, 0, 0); \
980+
else \
981+
ipv6nd_free_ra(rap); \
982+
977983
if (ifp == NULL || RS_STATE(ifp) == NULL) {
978984
#ifdef DEBUG_RS
979985
logdebugx("RA for unexpected interface from %s", sfrom);
@@ -1130,8 +1136,10 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx,
11301136
memcpy(&ndo, p, sizeof(ndo));
11311137
olen = (size_t)ndo.nd_opt_len * 8;
11321138
if (olen == 0) {
1139+
/* RFC4681 4.6 says we MUST discard this ND packet. */
11331140
logerrx("%s: zero length option", ifp->name);
1134-
break;
1141+
FREE_RAP(rap);
1142+
return;
11351143
}
11361144
if (olen > len) {
11371145
logerrx("%s: option length exceeds message",
@@ -1155,10 +1163,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx,
11551163
else
11561164
logwarnx("%s: reject RA (option %d) from %s",
11571165
ifp->name, ndo.nd_opt_type, rap->sfrom);
1158-
if (new_rap)
1159-
ipv6nd_removefreedrop_ra(rap, 0, 0);
1160-
else
1161-
ipv6nd_free_ra(rap);
1166+
FREE_RAP(rap);
11621167
return;
11631168
}
11641169

@@ -1409,10 +1414,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx,
14091414
{
14101415
logwarnx("%s: reject RA (no option %s) from %s",
14111416
ifp->name, dho->var, rap->sfrom);
1412-
if (new_rap)
1413-
ipv6nd_removefreedrop_ra(rap, 0, 0);
1414-
else
1415-
ipv6nd_free_ra(rap);
1417+
FREE_RAP(rap);
14161418
return;
14171419
}
14181420
}
@@ -1494,6 +1496,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx,
14941496

14951497
/* Expire should be called last as the rap object could be destroyed */
14961498
ipv6nd_expirera(ifp);
1499+
#undef FREE_RAP
14971500
}
14981501

14991502
bool

0 commit comments

Comments
 (0)