cloned interface malloc wait

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

cloned interface malloc wait

Alexander Bluhm
Hi,

Creating a cloned interface could return ENOMEM during a temporary
memory shortage.  As it is invoked from a system call, it should
not fail and wait instead.

ok?

bluhm

Index: net/if_bridge.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_bridge.c,v
retrieving revision 1.299
diff -u -p -r1.299 if_bridge.c
--- net/if_bridge.c 20 Nov 2017 10:17:40 -0000 1.299
+++ net/if_bridge.c 9 Jan 2018 00:13:05 -0000
@@ -156,10 +156,7 @@ bridge_clone_create(struct if_clone *ifc
  struct ifnet *ifp;
  int i;
 
- sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT|M_ZERO);
- if (!sc)
- return (ENOMEM);
-
+ sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
  sc->sc_stp = bstp_create(&sc->sc_if);
  if (!sc->sc_stp) {
  free(sc, M_DEVBUF, sizeof *sc);
Index: net/if_etherip.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_etherip.c,v
retrieving revision 1.28
diff -u -p -r1.28 if_etherip.c
--- net/if_etherip.c 20 Nov 2017 10:35:24 -0000 1.28
+++ net/if_etherip.c 9 Jan 2018 00:13:21 -0000
@@ -99,9 +99,7 @@ etherip_clone_create(struct if_clone *if
  struct ifnet *ifp;
  struct etherip_softc *sc;
 
- if ((sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
- return ENOMEM;
-
+ sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
  ifp = &sc->sc_ac.ac_if;
  snprintf(ifp->if_xname, sizeof ifp->if_xname, "etherip%d", unit);
  ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
Index: net/if_gif.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_gif.c,v
retrieving revision 1.105
diff -u -p -r1.105 if_gif.c
--- net/if_gif.c 20 Nov 2017 10:35:24 -0000 1.105
+++ net/if_gif.c 9 Jan 2018 00:13:32 -0000
@@ -107,10 +107,7 @@ gif_clone_create(struct if_clone *ifc, i
 {
  struct gif_softc *sc;
 
- sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT|M_ZERO);
- if (!sc)
- return (ENOMEM);
-
+ sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
  snprintf(sc->gif_if.if_xname, sizeof sc->gif_if.if_xname,
      "%s%d", ifc->ifc_name, unit);
  sc->gif_if.if_mtu    = GIF_MTU;
Index: net/if_gre.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_gre.c,v
retrieving revision 1.88
diff -u -p -r1.88 if_gre.c
--- net/if_gre.c 20 Oct 2017 09:35:09 -0000 1.88
+++ net/if_gre.c 9 Jan 2018 00:13:45 -0000
@@ -122,14 +122,11 @@ gre_clone_create(struct if_clone *ifc, i
 {
  struct gre_softc *sc;
 
- sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT|M_ZERO);
- if (!sc)
- return (ENOMEM);
+ sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
  snprintf(sc->sc_if.if_xname, sizeof sc->sc_if.if_xname, "%s%d",
     ifc->ifc_name, unit);
  sc->sc_if.if_softc = sc;
  sc->sc_if.if_type = IFT_TUNNEL;
- sc->sc_if.if_addrlen = 0;
  sc->sc_if.if_hdrlen = 24; /* IP + GRE */
  sc->sc_if.if_mtu = GREMTU;
  sc->sc_if.if_flags = IFF_POINTOPOINT|IFF_MULTICAST;
@@ -137,11 +134,6 @@ gre_clone_create(struct if_clone *ifc, i
  sc->sc_if.if_output = gre_output;
  sc->sc_if.if_ioctl = gre_ioctl;
  sc->sc_if.if_rtrequest = p2p_rtrequest;
- sc->sc_if.if_collisions = 0;
- sc->sc_if.if_ierrors = 0;
- sc->sc_if.if_oerrors = 0;
- sc->sc_if.if_ipackets = 0;
- sc->sc_if.if_opackets = 0;
  sc->g_dst.s_addr = sc->g_src.s_addr = INADDR_ANY;
  sc->sc_ka_state = GRE_STATE_UKNWN;
 
Index: net/if_loop.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_loop.c,v
retrieving revision 1.84
diff -u -p -r1.84 if_loop.c
--- net/if_loop.c 15 Dec 2017 01:37:30 -0000 1.84
+++ net/if_loop.c 9 Jan 2018 00:00:07 -0000
@@ -167,10 +167,7 @@ loop_clone_create(struct if_clone *ifc,
 {
  struct ifnet *ifp;
 
- ifp = malloc(sizeof(*ifp), M_DEVBUF, M_NOWAIT|M_ZERO);
- if (ifp == NULL)
- return (ENOMEM);
-
+ ifp = malloc(sizeof(*ifp), M_DEVBUF, M_WAITOK|M_ZERO);
  snprintf(ifp->if_xname, sizeof ifp->if_xname, "lo%d", unit);
  ifp->if_softc = NULL;
  ifp->if_mtu = LOMTU;
@@ -181,7 +178,6 @@ loop_clone_create(struct if_clone *ifc,
  ifp->if_output = looutput;
  ifp->if_type = IFT_LOOP;
  ifp->if_hdrlen = sizeof(u_int32_t);
- ifp->if_addrlen = 0;
  if (unit == 0) {
  if_attachhead(ifp);
  if_addgroup(ifp, ifc->ifc_name);
Index: net/if_mpe.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_mpe.c,v
retrieving revision 1.63
diff -u -p -r1.63 if_mpe.c
--- net/if_mpe.c 29 Nov 2017 19:36:03 -0000 1.63
+++ net/if_mpe.c 9 Jan 2018 00:00:28 -0000
@@ -81,10 +81,7 @@ mpe_clone_create(struct if_clone *ifc, i
  struct ifnet *ifp;
  struct mpe_softc *mpeif;
 
- if ((mpeif = malloc(sizeof(*mpeif),
-    M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
- return (ENOMEM);
-
+ mpeif = malloc(sizeof(*mpeif), M_DEVBUF, M_WAITOK|M_ZERO);
  mpeif->sc_unit = unit;
  ifp = &mpeif->sc_if;
  snprintf(ifp->if_xname, sizeof ifp->if_xname, "mpe%d", unit);
Index: net/if_mpw.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_mpw.c,v
retrieving revision 1.22
diff -u -p -r1.22 if_mpw.c
--- net/if_mpw.c 15 May 2017 14:03:53 -0000 1.22
+++ net/if_mpw.c 9 Jan 2018 00:00:46 -0000
@@ -83,10 +83,7 @@ mpw_clone_create(struct if_clone *ifc, i
  struct mpw_softc *sc;
  struct ifnet *ifp;
 
- sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT | M_ZERO);
- if (sc == NULL)
- return (ENOMEM);
-
+ sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
  ifp = &sc->sc_if;
  snprintf(ifp->if_xname, sizeof(ifp->if_xname), "mpw%d", unit);
  ifp->if_softc = sc;
Index: net/if_pair.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_pair.c,v
retrieving revision 1.10
diff -u -p -r1.10 if_pair.c
--- net/if_pair.c 23 Jan 2017 11:37:29 -0000 1.10
+++ net/if_pair.c 9 Jan 2018 00:01:27 -0000
@@ -108,10 +108,7 @@ pair_clone_create(struct if_clone *ifc,
  struct ifnet *ifp;
  struct pair_softc *sc;
 
- if ((sc = malloc(sizeof(*sc),
-    M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
- return (ENOMEM);
-
+ sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
  ifp = &sc->sc_ac.ac_if;
  snprintf(ifp->if_xname, sizeof ifp->if_xname, "pair%d", unit);
  ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
Index: net/if_pflog.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_pflog.c,v
retrieving revision 1.80
diff -u -p -r1.80 if_pflog.c
--- net/if_pflog.c 11 Aug 2017 21:24:19 -0000 1.80
+++ net/if_pflog.c 9 Jan 2018 00:01:59 -0000
@@ -137,10 +137,7 @@ pflog_clone_create(struct if_clone *ifc,
  struct ifnet *ifp;
  struct pflog_softc *pflogif;
 
- if ((pflogif = malloc(sizeof(*pflogif),
-    M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
- return (ENOMEM);
-
+ pflogif = malloc(sizeof(*pflogif), M_DEVBUF, M_WAITOK|M_ZERO);
  pflogif->sc_unit = unit;
  ifp = &pflogif->sc_if;
  snprintf(ifp->if_xname, sizeof ifp->if_xname, "pflog%d", unit);
Index: net/if_pflow.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_pflow.c,v
retrieving revision 1.85
diff -u -p -r1.85 if_pflow.c
--- net/if_pflow.c 31 Oct 2017 22:05:12 -0000 1.85
+++ net/if_pflow.c 9 Jan 2018 00:03:19 -0000
@@ -145,12 +145,8 @@ pflow_clone_create(struct if_clone *ifc,
  struct ifnet *ifp;
  struct pflow_softc *pflowif;
 
- if ((pflowif = malloc(sizeof(*pflowif),
-    M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
- return (ENOMEM);
-
+ pflowif = malloc(sizeof(*pflowif), M_DEVBUF, M_WAITOK|M_ZERO);
  MGET(pflowif->send_nam, M_WAIT, MT_SONAME);
-
  pflowif->sc_version = PFLOW_PROTO_DEFAULT;
 
  /* ipfix template init */
Index: net/if_pfsync.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_pfsync.c,v
retrieving revision 1.255
diff -u -p -r1.255 if_pfsync.c
--- net/if_pfsync.c 20 Nov 2017 10:35:24 -0000 1.255
+++ net/if_pfsync.c 9 Jan 2018 00:05:11 -0000
@@ -300,8 +300,7 @@ pfsync_clone_create(struct if_clone *ifc
 
  pfsync_sync_ok = 1;
 
- sc = malloc(sizeof(*pfsyncif), M_DEVBUF, M_WAITOK | M_ZERO);
-
+ sc = malloc(sizeof(*pfsyncif), M_DEVBUF, M_WAITOK|M_ZERO);
  for (q = 0; q < PFSYNC_S_COUNT; q++)
  TAILQ_INIT(&sc->sc_qs[q]);
 
Index: net/if_ppp.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_ppp.c,v
retrieving revision 1.109
diff -u -p -r1.109 if_ppp.c
--- net/if_ppp.c 11 Aug 2017 21:24:19 -0000 1.109
+++ net/if_ppp.c 9 Jan 2018 00:15:29 -0000
@@ -205,10 +205,7 @@ ppp_clone_create(struct if_clone *ifc, i
 {
  struct ppp_softc *sc;
 
- sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT|M_ZERO);
- if (!sc)
- return (ENOMEM);
-
+ sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
  sc->sc_unit = unit;
  snprintf(sc->sc_if.if_xname, sizeof sc->sc_if.if_xname, "%s%d",
     ifc->ifc_name, unit);
Index: net/if_pppoe.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_pppoe.c,v
retrieving revision 1.65
diff -u -p -r1.65 if_pppoe.c
--- net/if_pppoe.c 8 Sep 2017 05:36:53 -0000 1.65
+++ net/if_pppoe.c 9 Jan 2018 00:15:54 -0000
@@ -196,10 +196,7 @@ pppoe_clone_create(struct if_clone *ifc,
  struct pppoe_softc *sc, *tmpsc;
  u_int32_t unique;
 
-        sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_CANFAIL|M_ZERO);
-        if (sc == NULL)
-                return (ENOMEM);
-
+ sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
  snprintf(sc->sc_sppp.pp_if.if_xname,
  sizeof(sc->sc_sppp.pp_if.if_xname),
  "pppoe%d", unit);
Index: net/if_switch.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_switch.c,v
retrieving revision 1.21
diff -u -p -r1.21 if_switch.c
--- net/if_switch.c 20 Nov 2017 10:17:40 -0000 1.21
+++ net/if_switch.c 9 Jan 2018 00:06:40 -0000
@@ -151,7 +151,6 @@ switch_clone_create(struct if_clone *ifc
 
  sc = malloc(sizeof(struct switch_softc), M_DEVBUF, M_WAITOK|M_ZERO);
  ifp = &sc->sc_if;
-
  snprintf(ifp->if_xname, sizeof ifp->if_xname, "switch%d", unit);
  ifp->if_softc = sc;
  ifp->if_mtu = ETHERMTU;
@@ -159,7 +158,6 @@ switch_clone_create(struct if_clone *ifc
  ifp->if_output = NULL;
  ifp->if_start = NULL;
  ifp->if_type = IFT_BRIDGE;
- ifp->if_addrlen = 0;
  ifp->if_hdrlen = ETHER_HDR_LEN;
  TAILQ_INIT(&sc->sc_swpo_list);
 
Index: net/if_trunk.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_trunk.c,v
retrieving revision 1.134
diff -u -p -r1.134 if_trunk.c
--- net/if_trunk.c 14 Aug 2017 08:31:00 -0000 1.134
+++ net/if_trunk.c 9 Jan 2018 00:17:09 -0000
@@ -157,9 +157,7 @@ trunk_clone_create(struct if_clone *ifc,
  struct ifnet *ifp;
  int i, error = 0;
 
- if ((tr = malloc(sizeof *tr, M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
- return (ENOMEM);
-
+ tr = malloc(sizeof(*tr), M_DEVBUF, M_WAITOK|M_ZERO);
  tr->tr_unit = unit;
  tr->tr_proto = TRUNK_PROTO_NONE;
  for (i = 0; trunk_protos[i].ti_proto != TRUNK_PROTO_NONE; i++) {
Index: net/if_tun.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_tun.c,v
retrieving revision 1.179
diff -u -p -r1.179 if_tun.c
--- net/if_tun.c 30 Dec 2017 23:08:29 -0000 1.179
+++ net/if_tun.c 9 Jan 2018 00:07:50 -0000
@@ -193,10 +193,7 @@ tun_create(struct if_clone *ifc, int uni
  struct tun_softc *tp;
  struct ifnet *ifp;
 
- tp = malloc(sizeof(*tp), M_DEVBUF, M_NOWAIT|M_ZERO);
- if (tp == NULL)
- return (ENOMEM);
-
+ tp = malloc(sizeof(*tp), M_DEVBUF, M_WAITOK|M_ZERO);
  tp->tun_unit = unit;
  tp->tun_flags = TUN_INITED|TUN_STAYUP;
 
Index: net/if_vether.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_vether.c,v
retrieving revision 1.29
diff -u -p -r1.29 if_vether.c
--- net/if_vether.c 22 Jan 2017 10:17:39 -0000 1.29
+++ net/if_vether.c 9 Jan 2018 00:08:17 -0000
@@ -75,10 +75,7 @@ vether_clone_create(struct if_clone *ifc
  struct ifnet *ifp;
  struct vether_softc *sc;
 
- if ((sc = malloc(sizeof(*sc),
-    M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
- return (ENOMEM);
-
+ sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
  ifp = &sc->sc_ac.ac_if;
  snprintf(ifp->if_xname, sizeof ifp->if_xname, "vether%d", unit);
  ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
Index: net/if_vlan.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_vlan.c,v
retrieving revision 1.174
diff -u -p -r1.174 if_vlan.c
--- net/if_vlan.c 22 Jun 2017 11:34:51 -0000 1.174
+++ net/if_vlan.c 9 Jan 2018 00:08:41 -0000
@@ -157,10 +157,7 @@ vlan_clone_create(struct if_clone *ifc,
  struct ifvlan *ifv;
  struct ifnet *ifp;
 
- ifv = malloc(sizeof(*ifv), M_DEVBUF, M_NOWAIT|M_ZERO);
- if (ifv == NULL)
- return (ENOMEM);
-
+ ifv = malloc(sizeof(*ifv), M_DEVBUF, M_WAITOK|M_ZERO);
  LIST_INIT(&ifv->vlan_mc_listhead);
  ifp = &ifv->ifv_if;
  ifp->if_softc = ifv;
Index: net/if_vxlan.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_vxlan.c,v
retrieving revision 1.64
diff -u -p -r1.64 if_vxlan.c
--- net/if_vxlan.c 20 Nov 2017 10:35:24 -0000 1.64
+++ net/if_vxlan.c 9 Jan 2018 00:18:34 -0000
@@ -125,10 +125,7 @@ vxlan_clone_create(struct if_clone *ifc,
  struct ifnet *ifp;
  struct vxlan_softc *sc;
 
- if ((sc = malloc(sizeof(*sc),
-    M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
- return (ENOMEM);
-
+ sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
  sc->sc_imo.imo_membership = malloc(
     (sizeof(struct in_multi *) * IP_MIN_MEMBERSHIPS), M_IPMOPTS,
     M_WAITOK|M_ZERO);
Index: netinet/ip_carp.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_carp.c,v
retrieving revision 1.320
diff -u -p -r1.320 ip_carp.c
--- netinet/ip_carp.c 23 Nov 2017 13:32:25 -0000 1.320
+++ netinet/ip_carp.c 9 Jan 2018 00:12:30 -0000
@@ -785,10 +785,7 @@ carp_clone_create(struct if_clone *ifc,
  struct carp_softc *sc;
  struct ifnet *ifp;
 
- sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT|M_ZERO);
- if (!sc)
- return (ENOMEM);
-
+ sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
  refcnt_init(&sc->sc_refcnt);
 
  SRPL_INIT(&sc->carp_vhosts);