From: jsg Date: Sun, 7 Jun 2015 12:02:28 +0000 (+0000) Subject: Introduce unhandled_af() for cases where code conditionally does X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ba4138390b9fd1585b0009db6ac54b8875efca33;p=openbsd 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@ --- 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 @@ -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)) { diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index 6a6db0ea0e1..15e69aead3a 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_input.c,v 1.291 2015/06/07 01:25:27 krw Exp $ */ +/* $OpenBSD: tcp_input.c,v 1.292 2015/06/07 12:02:28 jsg Exp $ */ /* $NetBSD: tcp_input.c,v 1.23 1996/02/13 23:43:44 christos Exp $ */ /* @@ -3262,7 +3262,9 @@ tcp_mss_adv(struct ifnet *ifp, int af) mss = IN6_LINKMTU(ifp); iphlen = sizeof(struct ip6_hdr); break; -#endif +#endif + default: + unhandled_af(af); } mss = mss - iphlen - sizeof(struct tcphdr); return (max(mss, tcp_mssdflt)); @@ -4203,7 +4205,7 @@ syn_cache_respond(struct syn_cache *sc, struct mbuf *m) break; #endif default: - th = NULL; + unhandled_af(sc->sc_src.sa.sa_family); } th->th_seq = htonl(sc->sc_iss); diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 52c81ee38de..8418b99a3df 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.124 2015/06/07 01:25:27 krw Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.125 2015/06/07 12:02:28 jsg Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -824,6 +824,8 @@ tcp_ident(void *oldp, size_t *oldlenp, void *newp, size_t newlen, int dodrop) inp = in_pcbhashlookup(&tcbtable, fin->sin_addr, fin->sin_port, lin->sin_addr, lin->sin_port, tir.rdomain); break; + default: + unhandled_af(tir.faddr.ss_family); } if (dodrop) {