icmp6: Count packets dropped due to an invalid hop limit

Pad the icmp6stat structure so that we can add more counters in the
future without breaking compatibility again, last done in r358620.
Annotate the rarely executed error paths with __predict_false while
here.

Reviewed by:	bz, melifaro
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D26578
This commit is contained in:
Mark Johnston 2020-10-19 17:07:19 +00:00
parent d80126a6f4
commit 4caea9b169
5 changed files with 14 additions and 5 deletions

View File

@ -639,6 +639,8 @@ struct icmp6stat {
uint64_t icp6s_overflowprfx; /* Too many prefixes. */
uint64_t icp6s_overflownndp; /* Too many neighbour entries. */
uint64_t icp6s_overflowredirect;/* Too many redirects. */
uint64_t icp6s_invlhlim; /* Invalid hop limit. */
uint64_t icp6s_spare[32];
};
#ifdef _KERNEL

View File

@ -2261,7 +2261,8 @@ icmp6_redirect_input(struct mbuf *m, int off)
ip6_sprintf(ip6buf, &src6)));
goto bad;
}
if (ip6->ip6_hlim != 255) {
if (__predict_false(ip6->ip6_hlim != 255)) {
ICMP6STAT_INC(icp6s_invlhlim);
nd6log((LOG_ERR,
"ICMP6 redirect sent from %s rejected; "
"hlim=%d (must be 255)\n",

View File

@ -136,7 +136,8 @@ nd6_ns_input(struct mbuf *m, int off, int icmp6len)
ifp = m->m_pkthdr.rcvif;
ip6 = mtod(m, struct ip6_hdr *);
if (ip6->ip6_hlim != 255) {
if (__predict_false(ip6->ip6_hlim != 255)) {
ICMP6STAT_INC(icp6s_invlhlim);
nd6log((LOG_ERR,
"nd6_ns_input: invalid hlim (%d) from %s to %s on %s\n",
ip6->ip6_hlim, ip6_sprintf(ip6bufs, &ip6->ip6_src),
@ -641,7 +642,8 @@ nd6_na_input(struct mbuf *m, int off, int icmp6len)
ifp = m->m_pkthdr.rcvif;
ip6 = mtod(m, struct ip6_hdr *);
if (ip6->ip6_hlim != 255) {
if (__predict_false(ip6->ip6_hlim != 255)) {
ICMP6STAT_INC(icp6s_invlhlim);
nd6log((LOG_ERR,
"nd6_na_input: invalid hlim (%d) from %s to %s on %s\n",
ip6->ip6_hlim, ip6_sprintf(ip6bufs, &ip6->ip6_src),

View File

@ -177,7 +177,8 @@ nd6_rs_input(struct mbuf *m, int off, int icmp6len)
/* Sanity checks */
ip6 = mtod(m, struct ip6_hdr *);
if (ip6->ip6_hlim != 255) {
if (__predict_false(ip6->ip6_hlim != 255)) {
ICMP6STAT_INC(icp6s_invlhlim);
nd6log((LOG_ERR,
"%s: invalid hlim (%d) from %s to %s on %s\n", __func__,
ip6->ip6_hlim, ip6_sprintf(ip6bufs, &ip6->ip6_src),
@ -376,7 +377,8 @@ nd6_ra_input(struct mbuf *m, int off, int icmp6len)
goto freeit;
ip6 = mtod(m, struct ip6_hdr *);
if (ip6->ip6_hlim != 255) {
if (__predict_false(ip6->ip6_hlim != 255)) {
ICMP6STAT_INC(icp6s_invlhlim);
nd6log((LOG_ERR,
"%s: invalid hlim (%d) from %s to %s on %s\n", __func__,
ip6->ip6_hlim, ip6_sprintf(ip6bufs, &ip6->ip6_src),

View File

@ -1063,6 +1063,8 @@ icmp6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
"{N:/neighbour entries overflow%s}\n");
p(icp6s_overflowredirect, "\t{:redirect-overflows/%ju} "
"{N:/redirect overflow%s}\n");
p(icp6s_invlhlim, "\t{:dropped-invalid-hop-limit/%ju} "
"{N:/message%s with invalid hop limit}\n");
xo_close_container("errors");
p(icp6s_pmtuchg, "\t{:path-mtu-changes/%ju} {N:/path MTU change%s}\n");
#undef p