diff options
| author | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2019-01-08 10:32:28 -0200 |
|---|---|---|
| committer | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2019-01-08 10:32:28 -0200 |
| commit | 75e710df7a21d980bba9e5b2260408a3b30d4145 (patch) | |
| tree | 0b7b786d9b68dcf55a0b1809648b156495148678 /zebra/kernel_socket.c | |
| parent | 19fb538dc116c837af3bb1a76526cbb9a39d1bfc (diff) | |
zebra: fix FreeBSD warning on fresh OS boot
Handle corner case where a warning log message is issued on interface
address netmask handling with sockaddr type AF_LINK: it may come empty
or with match all (all 0xFF).
In the first case all lengths are zero and we only need to copy the
first bytes, second case it comes with a zero index and all 0xFF bytes.
In any case we only need to figure out a few of the first bytes instead
of all data.
Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to 'zebra/kernel_socket.c')
| -rw-r--r-- | zebra/kernel_socket.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 1f82c1d591..29d2b1f45f 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -250,6 +250,7 @@ static inline int af_check(int family) size_t _rta_get(caddr_t sap, void *destp, size_t destlen, bool checkaf) { struct sockaddr *sa = (struct sockaddr *)sap; + struct sockaddr_dl *sdl; uint8_t *dest = destp; size_t tlen, copylen; @@ -263,6 +264,17 @@ size_t _rta_get(caddr_t sap, void *destp, size_t destlen, bool checkaf) if (copylen > 0 && dest != NULL) { if (checkaf && af_check(sa->sa_family) == 0) return tlen; + /* + * Handle sockaddr_dl corner case: + * RTA_NETMASK might be AF_LINK, but it doesn't anything + * relevant (e.g. zeroed out fields). Check for this + * case and avoid warning log message. + */ + if (sa->sa_family == AF_LINK) { + sdl = (struct sockaddr_dl *)sa; + if (sdl->sdl_index == 0 || sdl->sdl_nlen == 0) + copylen = sizeof(*sdl) - sizeof(sdl->sdl_data); + } if (copylen > destlen) { zlog_warn("%s: destination buffer too small (%lu vs %lu)", |
