summaryrefslogtreecommitdiff
path: root/sys/net
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2015-06-07 12:02:29 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2015-06-07 12:02:29 +0000
commit04017e9dbfe2df7961ed665add43b3e722a52096 (patch)
tree16cfcdc85f9465791f51b9afe4281fed867b5346 /sys/net
parent25ced7e80a0f1efb5d3a9b7422aec2463f86a1f3 (diff)
Introduce unhandled_af() for cases where code conditionally does
something based on an address family and later assumes one of the paths was taken. This was initially just calls to panic until guenther suggested a function to reduce the amount of strings needed. This reduces the amount of noise with static analysers and acts as a sanity check. ok guenther@ bluhm@
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/if.c8
-rw-r--r--sys/net/if.h3
-rw-r--r--sys/net/if_pflow.c6
-rw-r--r--sys/net/pf.c10
-rw-r--r--sys/net/pf_table.c31
5 files changed, 45 insertions, 13 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index d0474966d9d..9965ae8134d 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.337 2015/06/03 22:01:07 mikeb Exp $ */
+/* $OpenBSD: if.c,v 1.338 2015/06/07 12:02:28 jsg Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -2476,3 +2476,9 @@ niq_enlist(struct niqueue *niq, struct mbuf_list *ml)
return (rv);
}
+
+__dead void
+unhandled_af(int af)
+{
+ panic("unhandled af %d", af);
+}
diff --git a/sys/net/if.h b/sys/net/if.h
index aebcab02d72..49ec165bb72 100644
--- a/sys/net/if.h
+++ b/sys/net/if.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.h,v 1.163 2015/05/18 13:32:28 reyk Exp $ */
+/* $OpenBSD: if.h,v 1.164 2015/06/07 12:02:28 jsg Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
@@ -466,6 +466,7 @@ struct ifnet *if_get(unsigned int);
void ifnewlladdr(struct ifnet *);
void if_congestion(void);
int if_congested(void);
+__dead void unhandled_af(int);
#endif /* _KERNEL */
diff --git a/sys/net/if_pflow.c b/sys/net/if_pflow.c
index ac27853cfb5..6ff2adebd00 100644
--- a/sys/net/if_pflow.c
+++ b/sys/net/if_pflow.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_pflow.c,v 1.49 2014/12/19 17:14:39 tedu Exp $ */
+/* $OpenBSD: if_pflow.c,v 1.50 2015/06/07 12:02:28 jsg Exp $ */
/*
* Copyright (c) 2011 Florian Obser <florian@narrans.de>
@@ -1007,8 +1007,8 @@ pflow_sendout_ipfix(struct pflow_softc *sc, sa_family_t af)
set_length = sizeof(struct pflow_set_header)
+ sc->sc_count6 * sizeof(struct pflow_ipfix_flow6);
break;
- default: /* NOTREACHED */
- break;
+ default:
+ unhandled_af(af);
}
if (!(ifp->if_flags & IFF_RUNNING)) {
diff --git a/sys/net/pf.c b/sys/net/pf.c
index 7f5f1aeec10..0fcbd5f4289 100644
--- a/sys/net/pf.c
+++ b/sys/net/pf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf.c,v 1.917 2015/06/05 13:22:34 mikeb Exp $ */
+/* $OpenBSD: pf.c,v 1.918 2015/06/07 12:02:28 jsg Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -2332,6 +2332,8 @@ pf_send_tcp(const struct pf_rule *r, sa_family_t af,
len = sizeof(struct ip6_hdr) + tlen;
break;
#endif /* INET6 */
+ default:
+ unhandled_af(af);
}
/* create outgoing mbuf */
@@ -4494,6 +4496,8 @@ pf_test_state_icmp(struct pf_pdesc *pd, struct pf_state **state,
icmptype = pd->hdr.icmp6->icmp6_type;
break;
#endif /* INET6 */
+ default:
+ panic("unhandled proto %d", pd->proto);
}
if (pf_icmp_mapping(pd, icmptype, &icmp_dir, &virtual_id,
@@ -4684,6 +4688,8 @@ pf_test_state_icmp(struct pf_pdesc *pd, struct pf_state **state,
pd2.dst = (struct pf_addr *)&h2_6.ip6_dst;
break;
#endif /* INET6 */
+ default:
+ unhandled_af(pd->af);
}
switch (pd2.proto) {
@@ -5789,6 +5795,8 @@ pf_check_proto_cksum(struct pf_pdesc *pd, int off, int len, u_int8_t p,
sum = in6_cksum(pd->m, p, off, len);
break;
#endif /* INET6 */
+ default:
+ unhandled_af(af);
}
if (sum) {
switch (p) {
diff --git a/sys/net/pf_table.c b/sys/net/pf_table.c
index 81378621bd9..005d99fe41f 100644
--- a/sys/net/pf_table.c
+++ b/sys/net/pf_table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_table.c,v 1.108 2015/04/09 12:04:14 mikeb Exp $ */
+/* $OpenBSD: pf_table.c,v 1.109 2015/06/07 12:02:28 jsg Exp $ */
/*
* Copyright (c) 2002 Cedric Berger
@@ -792,12 +792,17 @@ pfr_lookup_addr(struct pfr_ktable *kt, struct pfr_addr *ad, int exact)
int s;
bzero(&sa, sizeof(sa));
- if (ad->pfra_af == AF_INET) {
+ switch (ad->pfra_af) {
+ case AF_INET:
FILLIN_SIN(sa.sin, ad->pfra_ip4addr);
head = kt->pfrkt_ip4;
- } else if ( ad->pfra_af == AF_INET6 ) {
+ break;
+ case AF_INET6:
FILLIN_SIN6(sa.sin6, ad->pfra_ip6addr);
head = kt->pfrkt_ip6;
+ break;
+ default:
+ unhandled_af(ad->pfra_af);
}
if (ADDR_NETWORK(ad)) {
pfr_prepare_network(&mask, ad->pfra_af, ad->pfra_net);
@@ -1042,10 +1047,16 @@ pfr_route_kentry(struct pfr_ktable *kt, struct pfr_kentry *ke)
int s;
bzero(ke->pfrke_node, sizeof(ke->pfrke_node));
- if (ke->pfrke_af == AF_INET)
+ switch (ke->pfrke_af) {
+ case AF_INET:
head = kt->pfrkt_ip4;
- else if (ke->pfrke_af == AF_INET6)
+ break;
+ case AF_INET6:
head = kt->pfrkt_ip6;
+ break;
+ default:
+ unhandled_af(ke->pfrke_af);
+ }
s = splsoftnet();
if (KENTRY_NETWORK(ke)) {
@@ -1066,10 +1077,16 @@ pfr_unroute_kentry(struct pfr_ktable *kt, struct pfr_kentry *ke)
struct radix_node_head *head;
int s;
- if (ke->pfrke_af == AF_INET)
+ switch (ke->pfrke_af) {
+ case AF_INET:
head = kt->pfrkt_ip4;
- else if (ke->pfrke_af == AF_INET6)
+ break;
+ case AF_INET6:
head = kt->pfrkt_ip6;
+ break;
+ default:
+ unhandled_af(ke->pfrke_af);
+ }
s = splsoftnet();
if (KENTRY_NETWORK(ke)) {