]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: make DEFINE_NETDEV_CAST() assert on input and output
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 21 Sep 2023 10:52:26 +0000 (12:52 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 22 Sep 2023 06:17:42 +0000 (08:17 +0200)
The macro used to return NULL if input was NULL or had the wrong type. Now
it asserts that input is nonnull and it has the expected type.

There are a few places where a missing or mismatched type was OK, but in a
majority of places, we would do both of the asserts. In various places we'd
only do one, but that was by ommission/mistake. So moving the asserts into the
macro allows us to save some lines.

23 files changed:
src/network/netdev/bareudp.c
src/network/netdev/batadv.c
src/network/netdev/bond.c
src/network/netdev/bridge.c
src/network/netdev/fou-tunnel.c
src/network/netdev/geneve.c
src/network/netdev/ipoib.c
src/network/netdev/ipvlan.c
src/network/netdev/l2tp-tunnel.c
src/network/netdev/macsec.c
src/network/netdev/macvlan.c
src/network/netdev/netdev.h
src/network/netdev/tunnel.c
src/network/netdev/veth.c
src/network/netdev/vlan.c
src/network/netdev/vrf.c
src/network/netdev/vxcan.c
src/network/netdev/vxlan.c
src/network/netdev/wireguard.c
src/network/netdev/wlan.c
src/network/netdev/xfrm.c
src/network/networkd-network.c
src/network/networkd-route.c

index 539f8486e5cf77a657663c429ec863e1fdfd2f7e..1df886573ba2cd23e330c392dc5b2a7671fd58a8 100644 (file)
@@ -21,10 +21,9 @@ DEFINE_CONFIG_PARSE_ENUM(config_parse_bare_udp_iftype, bare_udp_protocol, BareUD
                          "Failed to parse EtherType=");
 
 static int netdev_bare_udp_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
-        assert(netdev);
         assert(m);
 
-        BareUDP *u = ASSERT_PTR(BAREUDP(netdev));
+        BareUDP *u = BAREUDP(netdev);
         int r;
 
         r = sd_netlink_message_append_u16(m, IFLA_BAREUDP_ETHERTYPE, htobe16(u->iftype));
@@ -39,10 +38,9 @@ static int netdev_bare_udp_fill_message_create(NetDev *netdev, Link *link, sd_ne
 }
 
 static int netdev_bare_udp_verify(NetDev *netdev, const char *filename) {
-        assert(netdev);
         assert(filename);
 
-        BareUDP *u = ASSERT_PTR(BAREUDP(netdev));
+        BareUDP *u = BAREUDP(netdev);
 
         if (u->dest_port == 0)
                 return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
@@ -56,9 +54,7 @@ static int netdev_bare_udp_verify(NetDev *netdev, const char *filename) {
 }
 
 static void bare_udp_init(NetDev *netdev) {
-        assert(netdev);
-
-        BareUDP *u = ASSERT_PTR(BAREUDP(netdev));
+        BareUDP *u = BAREUDP(netdev);
 
         u->iftype = _BARE_UDP_PROTOCOL_INVALID;
 }
index 7e97619657a2ca39acfe58b46e3f115f7dd9bdba..26da0231d45996149adb0ca2ade6b7f81d28ca33 100644 (file)
@@ -16,9 +16,7 @@
 #include "string-util.h"
 
 static void batadv_init(NetDev *n) {
-        BatmanAdvanced *b;
-
-        b = BATADV(n);
+        BatmanAdvanced *b = BATADV(n);
 
         /* Set defaults */
         b->aggregation            = true;
@@ -115,11 +113,9 @@ static int netdev_batman_set_handler(sd_netlink *rtnl, sd_netlink_message *m, Ne
 }
 
 static int netdev_batadv_post_create_message(NetDev *netdev, sd_netlink_message *message) {
-        BatmanAdvanced *b;
+        BatmanAdvanced *b = BATADV(netdev);
         int r;
 
-        assert_se(b = BATADV(netdev));
-
         r = sd_netlink_message_append_u32(message, BATADV_ATTR_MESH_IFINDEX, netdev->ifindex);
         if (r < 0)
                 return r;
@@ -188,14 +184,10 @@ static int netdev_batadv_post_create(NetDev *netdev, Link *link) {
 }
 
 static int netdev_batadv_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
-        BatmanAdvanced *b;
-        int r;
-
-        assert(netdev);
         assert(m);
 
-        b = BATADV(netdev);
-        assert(b);
+        BatmanAdvanced *b = BATADV(netdev);
+        int r;
 
         r = sd_netlink_message_append_string(m, IFLA_BATADV_ALGO_NAME, batadv_routing_algorithm_kernel_to_string(b->routing_algorithm));
         if (r < 0)
index 6bedf0cd3eaa32defb9a7f956181f1c66af12372..4d75a0d6bf224abdd45fef12107ff3785fccd88a 100644 (file)
@@ -57,11 +57,10 @@ DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_arp_all_targets, bond_arp_all_targets
 DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_primary_reselect, bond_primary_reselect, BondPrimaryReselect, "Failed to parse bond primary reselect");
 
 static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
-        assert(netdev);
         assert(!link);
         assert(m);
 
-        Bond *b = ASSERT_PTR(BOND(netdev));
+        Bond *b = BOND(netdev);
         int r;
 
         if (b->mode != _NETDEV_BOND_MODE_INVALID) {
@@ -238,7 +237,7 @@ int config_parse_arp_ip_target_address(
         assert(rvalue);
         assert(data);
 
-        Bond *b = ASSERT_PTR(BOND(userdata));
+        Bond *b = BOND(userdata);
         int r;
 
         if (isempty(rvalue)) {
@@ -378,17 +377,13 @@ int config_parse_ad_actor_system(
 }
 
 static void bond_done(NetDev *netdev) {
-        assert(netdev);
-
-        Bond *b = ASSERT_PTR(BOND(netdev));
+        Bond *b = BOND(netdev);
 
         ordered_set_free(b->arp_ip_targets);
 }
 
 static void bond_init(NetDev *netdev) {
-        assert(netdev);
-
-        Bond *b = ASSERT_PTR(BOND(netdev));
+        Bond *b = BOND(netdev);
 
         b->mode = _NETDEV_BOND_MODE_INVALID;
         b->xmit_hash_policy = _NETDEV_BOND_XMIT_HASH_POLICY_INVALID;
index 19638a871f84951618c4ad484b32e625991c027c..3e394edadfd331e8e9a75e8db4cdd74eada2da9e 100644 (file)
@@ -46,9 +46,7 @@ static int netdev_bridge_set_handler(sd_netlink *rtnl, sd_netlink_message *m, Ne
 }
 
 static int netdev_bridge_post_create_message(NetDev *netdev, sd_netlink_message *req) {
-        assert(netdev);
-
-        Bridge *b = ASSERT_PTR(BRIDGE(netdev));
+        Bridge *b = BRIDGE(netdev);
         int r;
 
         r = sd_netlink_message_open_container(req, IFLA_LINKINFO);
@@ -232,7 +230,7 @@ int config_parse_bridge_port_priority(
 }
 
 static void bridge_init(NetDev *netdev) {
-        Bridge *b = ASSERT_PTR(BRIDGE(netdev));
+        Bridge *b = BRIDGE(netdev);
 
         b->mcast_querier = -1;
         b->mcast_snooping = -1;
index 12e8e462a217326f585f81dc500a29edd6158c66..3bf41a8bf2979f988d922f03e8150b81a2659317 100644 (file)
@@ -24,9 +24,7 @@ DEFINE_CONFIG_PARSE_ENUM(config_parse_fou_encap_type, fou_encap_type, FooOverUDP
                          "Failed to parse Encapsulation=");
 
 static int netdev_fill_fou_tunnel_message(NetDev *netdev, sd_netlink_message *m) {
-        assert(netdev);
-
-        FouTunnel *t = ASSERT_PTR(FOU(netdev));
+        FouTunnel *t = FOU(netdev);
         uint8_t encap_type;
         int r;
 
@@ -128,7 +126,6 @@ static int netdev_fou_tunnel_create(NetDev *netdev) {
         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
         int r;
 
-        assert(netdev);
         assert(FOU(netdev));
 
         r = netdev_create_fou_tunnel_message(netdev, &m);
@@ -220,10 +217,9 @@ int config_parse_fou_tunnel_address(
 }
 
 static int netdev_fou_tunnel_verify(NetDev *netdev, const char *filename) {
-        assert(netdev);
         assert(filename);
 
-        FouTunnel *t = ASSERT_PTR(FOU(netdev));
+        FouTunnel *t = FOU(netdev);
 
         switch (t->fou_encap_type) {
         case NETDEV_FOO_OVER_UDP_ENCAP_DIRECT:
@@ -254,13 +250,7 @@ static int netdev_fou_tunnel_verify(NetDev *netdev, const char *filename) {
 }
 
 static void fou_tunnel_init(NetDev *netdev) {
-        FouTunnel *t;
-
-        assert(netdev);
-
-        t = FOU(netdev);
-
-        assert(t);
+        FouTunnel *t = FOU(netdev);
 
         t->fou_encap_type = NETDEV_FOO_OVER_UDP_ENCAP_DIRECT;
 }
index 5615f5bdcea211f6002e5c56e48062ec4eddd125..bc655ec7ffd9960a38ad8905421a385aaaefb8fb 100644 (file)
@@ -28,10 +28,9 @@ DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(geneve_df, GeneveDF, NETDEV_GENEVE_DF_YE
 DEFINE_CONFIG_PARSE_ENUM(config_parse_geneve_df, geneve_df, GeneveDF, "Failed to parse Geneve IPDoNotFragment= setting");
 
 static int netdev_geneve_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
-        assert(netdev);
         assert(m);
 
-        Geneve *v = ASSERT_PTR(GENEVE(netdev));
+        Geneve *v = GENEVE(netdev);
         int r;
 
         if (v->id <= GENEVE_VID_MAX) {
@@ -243,10 +242,9 @@ int config_parse_geneve_ttl(
 }
 
 static int netdev_geneve_verify(NetDev *netdev, const char *filename) {
-        assert(netdev);
         assert(filename);
 
-        Geneve *v = ASSERT_PTR(GENEVE(netdev));
+        Geneve *v = GENEVE(netdev);
 
         if (v->id > GENEVE_VID_MAX)
                 return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
@@ -256,9 +254,7 @@ static int netdev_geneve_verify(NetDev *netdev, const char *filename) {
 }
 
 static void geneve_init(NetDev *netdev) {
-        assert(netdev);
-
-        Geneve *v = ASSERT_PTR(GENEVE(netdev));
+        Geneve *v = GENEVE(netdev);
 
         v->id = GENEVE_VID_MAX + 1;
         v->geneve_df = _NETDEV_GENEVE_DF_INVALID;
index 5dd9286d57f5407c909440035c5e15ddd6e74103..d5fe299b7b43d0f1a8605a9094609f5ff1cdf40b 100644 (file)
@@ -12,29 +12,18 @@ assert_cc((int) IP_OVER_INFINIBAND_MODE_DATAGRAM  == (int) IPOIB_MODE_DATAGRAM);
 assert_cc((int) IP_OVER_INFINIBAND_MODE_CONNECTED == (int) IPOIB_MODE_CONNECTED);
 
 static void netdev_ipoib_init(NetDev *netdev) {
-        IPoIB *ipoib;
-
-        assert(netdev);
-
-        ipoib = IPOIB(netdev);
-
-        assert(ipoib);
+        IPoIB *ipoib = IPOIB(netdev);
 
         ipoib->mode = _IP_OVER_INFINIBAND_MODE_INVALID;
         ipoib->umcast = -1;
 }
 
 static int netdev_ipoib_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
-        IPoIB *ipoib;
-        int r;
-
-        assert(netdev);
         assert(link);
         assert(m);
 
-        ipoib = IPOIB(netdev);
-
-        assert(ipoib);
+        IPoIB *ipoib = IPOIB(netdev);
+        int r;
 
         if (ipoib->pkey > 0) {
                 r = sd_netlink_message_append_u16(m, IFLA_IPOIB_PKEY, ipoib->pkey);
index 058eadebd7a3cdb6115e47322c76dbf8a3783499..05d5d010f65c7b74db53359d60a31c8ccdd07422 100644 (file)
@@ -14,19 +14,12 @@ DEFINE_CONFIG_PARSE_ENUM(config_parse_ipvlan_mode, ipvlan_mode, IPVlanMode, "Fai
 DEFINE_CONFIG_PARSE_ENUM(config_parse_ipvlan_flags, ipvlan_flags, IPVlanFlags, "Failed to parse ipvlan flags");
 
 static int netdev_ipvlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
-        IPVlan *m;
-        int r;
-
         assert(netdev);
         assert(link);
         assert(netdev->ifname);
 
-        if (netdev->kind == NETDEV_KIND_IPVLAN)
-                m = IPVLAN(netdev);
-        else
-                m = IPVTAP(netdev);
-
-        assert(m);
+        IPVlan *m = netdev->kind == NETDEV_KIND_IPVLAN ? IPVLAN(netdev) : IPVTAP(netdev);
+        int r;
 
         if (m->mode != _NETDEV_IPVLAN_MODE_INVALID) {
                 r = sd_netlink_message_append_u16(req, IFLA_IPVLAN_MODE, m->mode);
@@ -43,17 +36,8 @@ static int netdev_ipvlan_fill_message_create(NetDev *netdev, Link *link, sd_netl
         return 0;
 }
 
-static void ipvlan_init(NetDev *n) {
-        IPVlan *m;
-
-        assert(n);
-
-        if (n->kind == NETDEV_KIND_IPVLAN)
-                m = IPVLAN(n);
-        else
-                m = IPVTAP(n);
-
-        assert(m);
+static void ipvlan_init(NetDev *netdev) {
+        IPVlan *m = ASSERT_PTR(netdev)->kind == NETDEV_KIND_IPVLAN ? IPVLAN(netdev) : IPVTAP(netdev);
 
         m->mode = _NETDEV_IPVLAN_MODE_INVALID;
         m->flags = _NETDEV_IPVLAN_FLAGS_INVALID;
@@ -80,13 +64,10 @@ const NetDevVTable ipvtap_vtable = {
 };
 
 IPVlanMode link_get_ipvlan_mode(Link *link) {
-        IPVlan *ipvlan;
-
         assert(link);
 
-        ipvlan = IPVLAN(link->netdev);
-        if (!ipvlan)
+        if (!link->netdev || link->netdev->kind != NETDEV_KIND_IPVLAN)
                 return _NETDEV_IPVLAN_MODE_INVALID;
 
-        return ipvlan->mode;
+        return IPVLAN(link->netdev)->mode;
 }
index 17d5391cd38698fc35ebf8477614082dd3236709..8b9406bb08112a883bbd3dd9eff679a7b18576a7 100644 (file)
@@ -92,15 +92,13 @@ static int l2tp_session_new_static(L2tpTunnel *t, const char *filename, unsigned
 }
 
 static int netdev_l2tp_create_message_tunnel(NetDev *netdev, union in_addr_union *local_address, sd_netlink_message **ret) {
+        assert(local_address);
+
         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
         uint16_t encap_type;
-        L2tpTunnel *t;
+        L2tpTunnel *t = L2TP(netdev);
         int r;
 
-        assert(netdev);
-        assert(local_address);
-        assert_se(t = L2TP(netdev));
-
         r = sd_genl_message_new(netdev->manager->genl, L2TP_GENL_NAME, L2TP_CMD_TUNNEL_CREATE, &m);
         if (r < 0)
                 return r;
@@ -278,13 +276,11 @@ static int link_get_l2tp_local_address(Link *link, L2tpTunnel *t, union in_addr_
 
 static int l2tp_get_local_address(NetDev *netdev, union in_addr_union *ret) {
         Link *link = NULL;
-        L2tpTunnel *t;
+        L2tpTunnel *t = L2TP(netdev);
         Address *a = NULL;
         int r;
 
-        assert(netdev);
         assert(netdev->manager);
-        assert_se(t = L2TP(netdev));
 
         if (t->local_ifname) {
                 r = link_get_by_name(netdev->manager, t->local_ifname, &link);
@@ -403,16 +399,11 @@ static int l2tp_create_session(NetDev *netdev, L2tpSession *session) {
 
 static int l2tp_create_tunnel_handler(sd_netlink *rtnl, sd_netlink_message *m, NetDev *netdev) {
         L2tpSession *session;
-        L2tpTunnel *t;
+        L2tpTunnel *t = L2TP(netdev);
         int r;
 
-        assert(netdev);
         assert(netdev->state != _NETDEV_STATE_INVALID);
 
-        t = L2TP(netdev);
-
-        assert(t);
-
         r = sd_netlink_message_get_errno(m);
         if (r == -EEXIST)
                 log_netdev_info(netdev, "netdev exists, using existing without changing its parameters");
@@ -434,12 +425,9 @@ static int l2tp_create_tunnel_handler(sd_netlink *rtnl, sd_netlink_message *m, N
 static int l2tp_create_tunnel(NetDev *netdev) {
         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
         union in_addr_union local_address;
-        L2tpTunnel *t;
+        L2tpTunnel *t = L2TP(netdev);
         int r;
 
-        assert(netdev);
-        assert_se(t = L2TP(netdev));
-
         r = l2tp_get_local_address(netdev, &local_address);
         if (r < 0)
                 return log_netdev_error_errno(netdev, r, "Could not find local address.");
@@ -757,13 +745,7 @@ int config_parse_l2tp_session_name(
 }
 
 static void l2tp_tunnel_init(NetDev *netdev) {
-        L2tpTunnel *t;
-
-        assert(netdev);
-
-        t = L2TP(netdev);
-
-        assert(t);
+        L2tpTunnel *t = L2TP(netdev);
 
         t->l2tp_encap_type = NETDEV_L2TP_ENCAPTYPE_UDP;
         t->udp6_csum_rx = true;
@@ -797,15 +779,10 @@ static int l2tp_session_verify(L2tpSession *session) {
 }
 
 static int netdev_l2tp_tunnel_verify(NetDev *netdev, const char *filename) {
-        L2tpTunnel *t;
-        L2tpSession *session;
-
-        assert(netdev);
         assert(filename);
 
-        t = L2TP(netdev);
-
-        assert(t);
+        L2tpTunnel *t = L2TP(netdev);
+        L2tpSession *session;
 
         if (!IN_SET(t->family, AF_INET, AF_INET6))
                 return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
@@ -830,13 +807,7 @@ static int netdev_l2tp_tunnel_verify(NetDev *netdev, const char *filename) {
 }
 
 static void l2tp_tunnel_done(NetDev *netdev) {
-        L2tpTunnel *t;
-
-        assert(netdev);
-
-        t = L2TP(netdev);
-
-        assert(t);
+        L2tpTunnel *t = L2TP(netdev);
 
         ordered_hashmap_free_with_destructor(t->sessions_by_section, l2tp_session_free);
         free(t->local_ifname);
index 6469a97b29e826045b8f5b906ad2dbda5c01dad1..6d17d45059aade09d7462ac388c028c12f2b0517 100644 (file)
@@ -472,9 +472,7 @@ static int netdev_macsec_configure_transmit_association(NetDev *netdev, Transmit
 }
 
 static int netdev_macsec_configure(NetDev *netdev, Link *link) {
-        assert(netdev);
-
-        MACsec *s = ASSERT_PTR(MACSEC(netdev));
+        MACsec *s = MACSEC(netdev);
         TransmitAssociation *a;
         ReceiveChannel *c;
         int r;
@@ -495,10 +493,9 @@ static int netdev_macsec_configure(NetDev *netdev, Link *link) {
 }
 
 static int netdev_macsec_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
-        assert(netdev);
         assert(m);
 
-        MACsec *v = ASSERT_PTR(MACSEC(netdev));
+        MACsec *v = MACSEC(netdev);
         int r;
 
         if (v->port > 0) {
@@ -1118,6 +1115,8 @@ static int macsec_receive_association_verify(ReceiveAssociation *a) {
 }
 
 static int netdev_macsec_verify(NetDev *netdev, const char *filename) {
+        assert(filename);
+
         MACsec *v = MACSEC(netdev);
         TransmitAssociation *a;
         ReceiveAssociation *n;
@@ -1126,10 +1125,6 @@ static int netdev_macsec_verify(NetDev *netdev, const char *filename) {
         bool use_for_encoding;
         int r;
 
-        assert(netdev);
-        assert(v);
-        assert(filename);
-
         ORDERED_HASHMAP_FOREACH(c, v->receive_channels_by_section) {
                 r = macsec_receive_channel_verify(c);
                 if (r < 0)
@@ -1184,30 +1179,18 @@ static int netdev_macsec_verify(NetDev *netdev, const char *filename) {
 }
 
 static void macsec_init(NetDev *netdev) {
-        MACsec *v;
-
-        assert(netdev);
-
-        v = MACSEC(netdev);
-
-        assert(v);
+        MACsec *v = MACSEC(netdev);
 
         v->encrypt = -1;
 }
 
 static void macsec_done(NetDev *netdev) {
-        MACsec *t;
-
-        assert(netdev);
-
-        t = MACSEC(netdev);
-
-        assert(t);
+        MACsec *v = MACSEC(netdev);
 
-        ordered_hashmap_free_with_destructor(t->receive_channels, macsec_receive_channel_free);
-        ordered_hashmap_free_with_destructor(t->receive_channels_by_section, macsec_receive_channel_free);
-        ordered_hashmap_free_with_destructor(t->transmit_associations_by_section, macsec_transmit_association_free);
-        ordered_hashmap_free_with_destructor(t->receive_associations_by_section, macsec_receive_association_free);
+        ordered_hashmap_free_with_destructor(v->receive_channels, macsec_receive_channel_free);
+        ordered_hashmap_free_with_destructor(v->receive_channels_by_section, macsec_receive_channel_free);
+        ordered_hashmap_free_with_destructor(v->transmit_associations_by_section, macsec_transmit_association_free);
+        ordered_hashmap_free_with_destructor(v->receive_associations_by_section, macsec_receive_association_free);
 }
 
 const NetDevVTable macsec_vtable = {
index 6083cd2b44e6e73385017998a287f52227419a4a..203807e3a566112c4add57ae8c1f6446ee8f3138 100644 (file)
 DEFINE_CONFIG_PARSE_ENUM(config_parse_macvlan_mode, macvlan_mode, MacVlanMode, "Failed to parse macvlan mode");
 
 static int netdev_macvlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
-        MacVlan *m;
-        int r;
-
         assert(netdev);
-        assert(link);
         assert(netdev->ifname);
+        assert(link);
         assert(link->network);
 
-        if (netdev->kind == NETDEV_KIND_MACVLAN)
-                m = MACVLAN(netdev);
-        else
-                m = MACVTAP(netdev);
-
-        assert(m);
+        MacVlan *m = netdev->kind == NETDEV_KIND_MACVLAN ? MACVLAN(netdev) : MACVTAP(netdev);
+        int r;
 
         if (m->mode == NETDEV_MACVLAN_MODE_SOURCE && !set_isempty(m->match_source_mac)) {
                 const struct ether_addr *mac_addr;
@@ -103,32 +96,14 @@ int config_parse_macvlan_broadcast_queue_size(
                         &m->bc_queue_length);
 }
 
-static void macvlan_done(NetDev *n) {
-        MacVlan *m;
-
-        assert(n);
-
-        if (n->kind == NETDEV_KIND_MACVLAN)
-                m = MACVLAN(n);
-        else
-                m = MACVTAP(n);
-
-        assert(m);
+static void macvlan_done(NetDev *netdev) {
+        MacVlan *m = ASSERT_PTR(netdev)->kind == NETDEV_KIND_MACVLAN ? MACVLAN(netdev) : MACVTAP(netdev);
 
         set_free(m->match_source_mac);
 }
 
-static void macvlan_init(NetDev *n) {
-        MacVlan *m;
-
-        assert(n);
-
-        if (n->kind == NETDEV_KIND_MACVLAN)
-                m = MACVLAN(n);
-        else
-                m = MACVTAP(n);
-
-        assert(m);
+static void macvlan_init(NetDev *netdev) {
+        MacVlan *m = ASSERT_PTR(netdev)->kind == NETDEV_KIND_MACVLAN ? MACVLAN(netdev) : MACVTAP(netdev);
 
         m->mode = _NETDEV_MACVLAN_MODE_INVALID;
         m->bc_queue_length = UINT32_MAX;
index 49eadbb7a442e1c02ff1388d9fd1982abf65ab51..cb8cc8c6a9d46dd139b7bd9f239f3febfef63249 100644 (file)
@@ -182,14 +182,13 @@ extern const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX];
 #define NETDEV_VTABLE(n) ((n)->kind != _NETDEV_KIND_INVALID ? netdev_vtable[(n)->kind] : NULL)
 
 /* For casting a netdev into the various netdev kinds */
-#define DEFINE_NETDEV_CAST(UPPERCASE, MixedCase)                            \
-        static inline MixedCase* UPPERCASE(NetDev *n) {                     \
-                if (_unlikely_(!n ||                                        \
-                               n->kind != NETDEV_KIND_##UPPERCASE) ||       \
-                               n->state == _NETDEV_STATE_INVALID)           \
-                        return NULL;                                        \
-                                                                            \
-                return (MixedCase*) n;                                      \
+#define DEFINE_NETDEV_CAST(UPPERCASE, MixedCase)                        \
+        static inline MixedCase* UPPERCASE(NetDev *n) {                 \
+                assert(n);                                              \
+                assert(n->kind == NETDEV_KIND_##UPPERCASE);             \
+                assert(n->state < _NETDEV_STATE_MAX);                   \
+                                                                        \
+                return (MixedCase*) n;                                  \
         }
 
 /* For casting the various netdev kinds into a netdev */
index bafe696ae5fb4e81893289f5720c69101f773e8a..db84e7cf6eeb8070188ab577224876ffaf29583f 100644 (file)
@@ -199,17 +199,11 @@ static int tunnel_get_local_address(Tunnel *t, Link *link, union in_addr_union *
 }
 
 static int netdev_ipip_sit_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
-        union in_addr_union local;
-        Tunnel *t;
-        int r;
-
-        assert(netdev);
         assert(m);
 
-        if (netdev->kind == NETDEV_KIND_IPIP)
-                t = ASSERT_PTR(IPIP(netdev));
-        else
-                t = ASSERT_PTR(SIT(netdev));
+        union in_addr_union local;
+        Tunnel *t = ASSERT_PTR(netdev)->kind == NETDEV_KIND_IPIP ? IPIP(netdev) : SIT(netdev);
+        int r;
 
         if (t->external) {
                 r = sd_netlink_message_append_flag(m, IFLA_IPTUN_COLLECT_METADATA);
@@ -302,13 +296,13 @@ static int netdev_gre_erspan_fill_message_create(NetDev *netdev, Link *link, sd_
 
         switch (netdev->kind) {
         case NETDEV_KIND_GRE:
-                t = ASSERT_PTR(GRE(netdev));
+                t = GRE(netdev);
                 break;
         case NETDEV_KIND_ERSPAN:
-                t = ASSERT_PTR(ERSPAN(netdev));
+                t = ERSPAN(netdev);
                 break;
         case NETDEV_KIND_GRETAP:
-                t = ASSERT_PTR(GRETAP(netdev));
+                t = GRETAP(netdev);
                 break;
         default:
                 assert_not_reached();
@@ -446,9 +440,9 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netl
         assert(m);
 
         if (netdev->kind == NETDEV_KIND_IP6GRE)
-                t = ASSERT_PTR(IP6GRE(netdev));
+                t = IP6GRE(netdev);
         else
-                t = ASSERT_PTR(IP6GRETAP(netdev));
+                t = IP6GRETAP(netdev);
 
         if (t->external) {
                 r = sd_netlink_message_append_flag(m, IFLA_GRE_COLLECT_METADATA);
@@ -527,18 +521,13 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netl
 }
 
 static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
-        union in_addr_union local;
-        uint32_t ikey, okey;
-        Tunnel *t;
-        int r;
-
         assert(netdev);
         assert(m);
 
-        if (netdev->kind == NETDEV_KIND_VTI)
-                t = ASSERT_PTR(VTI(netdev));
-        else
-                t = ASSERT_PTR(VTI6(netdev));
+        union in_addr_union local;
+        uint32_t ikey, okey;
+        Tunnel *t = netdev->kind == NETDEV_KIND_VTI ? VTI(netdev) : VTI6(netdev);
+        int r;
 
         if (link || t->assign_to_loopback) {
                 r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link ? link->ifindex : LOOPBACK_IFINDEX);
@@ -582,7 +571,7 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netl
 
         union in_addr_union local;
         uint8_t proto;
-        Tunnel *t = ASSERT_PTR(IP6TNL(netdev));
+        Tunnel *t = IP6TNL(netdev);
         int r;
 
         switch (t->ip6tnl_mode) {
index fb00e6667fb60fb2d7b1b796e0c09accc19c13d2..e0f5b4ebb1a7c61a2046a981c4cbdb5d42a5ee07 100644 (file)
 #include "veth.h"
 
 static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
-        struct hw_addr_data hw_addr;
-        Veth *v;
-        int r;
-
-        assert(netdev);
         assert(!link);
         assert(m);
 
-        v = VETH(netdev);
-
-        assert(v);
+        struct hw_addr_data hw_addr;
+        Veth *v = VETH(netdev);
+        int r;
 
         r = sd_netlink_message_open_container(m, VETH_INFO_PEER);
         if (r < 0)
@@ -57,14 +52,9 @@ static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_netlin
 }
 
 static int netdev_veth_verify(NetDev *netdev, const char *filename) {
-        Veth *v;
-
-        assert(netdev);
         assert(filename);
 
-        v = VETH(netdev);
-
-        assert(v);
+        Veth *v = VETH(netdev);
 
         if (!v->ifname_peer)
                 return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
@@ -74,14 +64,8 @@ static int netdev_veth_verify(NetDev *netdev, const char *filename) {
         return 0;
 }
 
-static void veth_done(NetDev *n) {
-        Veth *v;
-
-        assert(n);
-
-        v = VETH(n);
-
-        assert(v);
+static void veth_done(NetDev *netdev) {
+        Veth *v = VETH(netdev);
 
         free(v->ifname_peer);
 }
index 5eb36ef6801f3fe4ea9511d7e366fb6667c0239f..2390206993b211491c3763c5d54c333ba3e8615b 100644 (file)
 #include "vlan.h"
 
 static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
-        struct ifla_vlan_flags flags = {};
-        VLan *v;
-        int r;
-
-        assert(netdev);
         assert(link);
         assert(req);
 
-        v = VLAN(netdev);
-
-        assert(v);
+        struct ifla_vlan_flags flags = {};
+        VLan *v = VLAN(netdev);
+        int r;
 
         r = sd_netlink_message_append_u16(req, IFLA_VLAN_ID, v->id);
         if (r < 0)
@@ -180,14 +175,9 @@ int config_parse_vlan_qos_maps(
 }
 
 static int netdev_vlan_verify(NetDev *netdev, const char *filename) {
-        VLan *v;
-
-        assert(netdev);
         assert(filename);
 
-        v = VLAN(netdev);
-
-        assert(v);
+        VLan *v = VLAN(netdev);
 
         if (v->id == VLANID_INVALID) {
                 log_netdev_warning(netdev, "VLAN without valid Id (%"PRIu16") configured in %s.", v->id, filename);
@@ -197,12 +187,8 @@ static int netdev_vlan_verify(NetDev *netdev, const char *filename) {
         return 0;
 }
 
-static void vlan_done(NetDev *n) {
-        VLan *v;
-
-        v = VLAN(n);
-
-        assert(v);
+static void vlan_done(NetDev *netdev) {
+        VLan *v = VLAN(netdev);
 
         set_free(v->egress_qos_maps);
         set_free(v->ingress_qos_maps);
@@ -211,9 +197,6 @@ static void vlan_done(NetDev *n) {
 static void vlan_init(NetDev *netdev) {
         VLan *v = VLAN(netdev);
 
-        assert(netdev);
-        assert(v);
-
         v->id = VLANID_INVALID;
         v->protocol = -1;
         v->gvrp = -1;
index 05ef3ff13d311a2e47836aa03ed3f560a1419cd6..b75ec2bcc686263956698155687ca5f01448265c 100644 (file)
@@ -7,16 +7,11 @@
 #include "vrf.h"
 
 static int netdev_vrf_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
-        Vrf *v;
-        int r;
-
-        assert(netdev);
         assert(!link);
         assert(m);
 
-        v = VRF(netdev);
-
-        assert(v);
+        Vrf *v = VRF(netdev);
+        int r;
 
         r = sd_netlink_message_append_u32(m, IFLA_VRF_TABLE, v->table);
         if (r < 0)
index 83269b070719e0c78f7d335b61f4e0604d394118..c0343f45b62171cb2e33920dfc185aa23dfdd9bc 100644 (file)
@@ -6,16 +6,11 @@
 #include "vxcan.h"
 
 static int netdev_vxcan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
-        VxCan *v;
-        int r;
-
-        assert(netdev);
         assert(!link);
         assert(m);
 
-        v = VXCAN(netdev);
-
-        assert(v);
+        VxCan *v = VXCAN(netdev);
+        int r;
 
         r = sd_netlink_message_open_container(m, VXCAN_INFO_PEER);
         if (r < 0)
@@ -35,14 +30,9 @@ static int netdev_vxcan_fill_message_create(NetDev *netdev, Link *link, sd_netli
 }
 
 static int netdev_vxcan_verify(NetDev *netdev, const char *filename) {
-        VxCan *v;
-
-        assert(netdev);
         assert(filename);
 
-        v = VXCAN(netdev);
-
-        assert(v);
+        VxCan *v = VXCAN(netdev);
 
         if (!v->ifname_peer)
                 return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
@@ -51,14 +41,8 @@ static int netdev_vxcan_verify(NetDev *netdev, const char *filename) {
         return 0;
 }
 
-static void vxcan_done(NetDev *n) {
-        VxCan *v;
-
-        assert(n);
-
-        v = VXCAN(n);
-
-        assert(v);
+static void vxcan_done(NetDev *netdev) {
+        VxCan *v = VXCAN(netdev);
 
         free(v->ifname_peer);
 }
index 2582ae8cab49bd81c6edf1a5d16575fc2dc0acb2..b11fdbbd0de05741c015da6def203f4c7fc500c4 100644 (file)
@@ -37,16 +37,11 @@ static int vxlan_get_local_address(VxLan *v, Link *link, int *ret_family, union
 }
 
 static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
-        union in_addr_union local;
-        int local_family, r;
-        VxLan *v;
-
-        assert(netdev);
         assert(m);
 
-        v = VXLAN(netdev);
-
-        assert(v);
+        union in_addr_union local;
+        int local_family, r;
+        VxLan *v = VXLAN(netdev);
 
         if (v->vni <= VXLAN_VID_MAX) {
                 r = sd_netlink_message_append_u32(m, IFLA_VXLAN_ID, v->vni);
@@ -376,12 +371,10 @@ int config_parse_vxlan_ttl(
 }
 
 static int netdev_vxlan_verify(NetDev *netdev, const char *filename) {
-        VxLan *v = VXLAN(netdev);
-
-        assert(netdev);
-        assert(v);
         assert(filename);
 
+        VxLan *v = VXLAN(netdev);
+
         if (v->vni > VXLAN_VID_MAX)
                 return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
                                                 "%s: VXLAN without valid VNI (or VXLAN Segment ID) configured. Ignoring.",
@@ -409,13 +402,7 @@ static int netdev_vxlan_verify(NetDev *netdev, const char *filename) {
 }
 
 static int netdev_vxlan_is_ready_to_create(NetDev *netdev, Link *link) {
-        VxLan *v;
-
-        assert(netdev);
-
-        v = VXLAN(netdev);
-
-        assert(v);
+        VxLan *v = VXLAN(netdev);
 
         if (v->independent)
                 return true;
@@ -424,13 +411,7 @@ static int netdev_vxlan_is_ready_to_create(NetDev *netdev, Link *link) {
 }
 
 static void vxlan_init(NetDev *netdev) {
-        VxLan *v;
-
-        assert(netdev);
-
-        v = VXLAN(netdev);
-
-        assert(v);
+        VxLan *v = VXLAN(netdev);
 
         v->local_type = _NETDEV_LOCAL_ADDRESS_TYPE_INVALID;
         v->vni = VXLAN_VID_MAX + 1;
index 0e992f9ad1b183e6d3afb0ecd8f455ddc80e2963..14f664e983071b335164e2cbc80273e6c19ef6bd 100644 (file)
@@ -228,13 +228,9 @@ static int wireguard_set_interface(NetDev *netdev) {
         WireguardPeer *peer_start;
         bool sent_once = false;
         uint32_t serial;
-        Wireguard *w;
+        Wireguard *w = WIREGUARD(netdev);
         int r;
 
-        assert(netdev);
-        w = WIREGUARD(netdev);
-        assert(w);
-
         for (peer_start = w->peers; peer_start || !sent_once; ) {
                 uint16_t i = 0;
 
@@ -428,11 +424,7 @@ static int peer_resolve_endpoint(WireguardPeer *peer) {
 }
 
 static void wireguard_resolve_endpoints(NetDev *netdev) {
-        Wireguard *w;
-
-        assert(netdev);
-        w = WIREGUARD(netdev);
-        assert(w);
+        Wireguard *w = WIREGUARD(netdev);
 
         LIST_FOREACH(peers, peer, w->peers)
                 if (peer_resolve_endpoint(peer) == -ENOBUFS)
@@ -441,7 +433,6 @@ static void wireguard_resolve_endpoints(NetDev *netdev) {
 }
 
 static int netdev_wireguard_post_create(NetDev *netdev, Link *link) {
-        assert(netdev);
         assert(WIREGUARD(netdev));
 
         (void) wireguard_set_interface(netdev);
@@ -537,11 +528,7 @@ int config_parse_wireguard_private_key(
                 void *data,
                 void *userdata) {
 
-        Wireguard *w;
-
-        assert(data);
-        w = WIREGUARD(data);
-        assert(w);
+        Wireguard *w = WIREGUARD(data);
 
         return wireguard_decode_key_and_warn(rvalue, w->private_key, unit, filename, line, lvalue);
 }
@@ -558,12 +545,8 @@ int config_parse_wireguard_private_key_file(
                 void *data,
                 void *userdata) {
 
+        Wireguard *w = WIREGUARD(data);
         _cleanup_free_ char *path = NULL;
-        Wireguard *w;
-
-        assert(data);
-        w = WIREGUARD(data);
-        assert(w);
 
         if (isempty(rvalue)) {
                 w->private_key_file = mfree(w->private_key_file);
@@ -592,14 +575,10 @@ int config_parse_wireguard_peer_key(
                 void *data,
                 void *userdata) {
 
+        Wireguard *w = WIREGUARD(data);
         _cleanup_(wireguard_peer_free_or_set_invalidp) WireguardPeer *peer = NULL;
-        Wireguard *w;
         int r;
 
-        assert(data);
-        w = WIREGUARD(data);
-        assert(w);
-
         r = wireguard_peer_new_static(w, filename, section_line, &peer);
         if (r < 0)
                 return log_oom();
@@ -626,15 +605,11 @@ int config_parse_wireguard_preshared_key_file(
                 void *data,
                 void *userdata) {
 
+        Wireguard *w = WIREGUARD(data);
         _cleanup_(wireguard_peer_free_or_set_invalidp) WireguardPeer *peer = NULL;
         _cleanup_free_ char *path = NULL;
-        Wireguard *w;
         int r;
 
-        assert(data);
-        w = WIREGUARD(data);
-        assert(w);
-
         r = wireguard_peer_new_static(w, filename, section_line, &peer);
         if (r < 0)
                 return log_oom();
@@ -669,19 +644,15 @@ int config_parse_wireguard_allowed_ips(
                 void *data,
                 void *userdata) {
 
+        assert(rvalue);
+
+        Wireguard *w = WIREGUARD(data);
         _cleanup_(wireguard_peer_free_or_set_invalidp) WireguardPeer *peer = NULL;
         union in_addr_union addr;
         unsigned char prefixlen;
         int r, family;
-        Wireguard *w;
         WireguardIPmask *ipmask;
 
-        assert(rvalue);
-        assert(data);
-
-        w = WIREGUARD(data);
-        assert(w);
-
         r = wireguard_peer_new_static(w, filename, section_line, &peer);
         if (r < 0)
                 return log_oom();
@@ -751,21 +722,18 @@ int config_parse_wireguard_endpoint(
                 void *data,
                 void *userdata) {
 
+        assert(filename);
+        assert(rvalue);
+        assert(userdata);
+
+        Wireguard *w = WIREGUARD(userdata);
         _cleanup_(wireguard_peer_free_or_set_invalidp) WireguardPeer *peer = NULL;
         _cleanup_free_ char *host = NULL;
         union in_addr_union addr;
         const char *p;
         uint16_t port;
-        Wireguard *w;
         int family, r;
 
-        assert(filename);
-        assert(rvalue);
-        assert(userdata);
-
-        w = WIREGUARD(userdata);
-        assert(w);
-
         r = wireguard_peer_new_static(w, filename, section_line, &peer);
         if (r < 0)
                 return log_oom();
@@ -846,17 +814,13 @@ int config_parse_wireguard_keepalive(
                 void *data,
                 void *userdata) {
 
+        assert(rvalue);
+
+        Wireguard *w = WIREGUARD(data);
         _cleanup_(wireguard_peer_free_or_set_invalidp) WireguardPeer *peer = NULL;
         uint16_t keepalive = 0;
-        Wireguard *w;
         int r;
 
-        assert(rvalue);
-        assert(data);
-
-        w = WIREGUARD(data);
-        assert(w);
-
         r = wireguard_peer_new_static(w, filename, section_line, &peer);
         if (r < 0)
                 return log_oom();
@@ -927,18 +891,14 @@ int config_parse_wireguard_peer_route_table(
                 void *data,
                 void *userdata) {
 
+        Wireguard *w = WIREGUARD(userdata);
         _cleanup_(wireguard_peer_free_or_set_invalidp) WireguardPeer *peer = NULL;
-        NetDev *netdev = ASSERT_PTR(userdata);
-        Wireguard *w;
         int r;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
-        assert(netdev->manager);
-
-        w = WIREGUARD(netdev);
-        assert(w);
+        assert(NETDEV(w)->manager);
 
         r = wireguard_peer_new_static(w, filename, section_line, &peer);
         if (r < 0)
@@ -957,7 +917,7 @@ int config_parse_wireguard_peer_route_table(
                 return 0;
         }
 
-        r = manager_get_route_table_from_string(netdev->manager, rvalue, &peer->route_table);
+        r = manager_get_route_table_from_string(NETDEV(w)->manager, rvalue, &peer->route_table);
         if (r < 0) {
                 log_syntax(unit, LOG_WARNING, filename, line, r,
                            "Failed to parse %s=, ignoring assignment: %s",
@@ -1051,21 +1011,13 @@ int config_parse_wireguard_peer_route_priority(
 }
 
 static void wireguard_init(NetDev *netdev) {
-        Wireguard *w;
-
-        assert(netdev);
-        w = WIREGUARD(netdev);
-        assert(w);
+        Wireguard *w = WIREGUARD(netdev);
 
         w->flags = WGDEVICE_F_REPLACE_PEERS;
 }
 
 static void wireguard_done(NetDev *netdev) {
-        Wireguard *w;
-
-        assert(netdev);
-        w = WIREGUARD(netdev);
-        assert(w);
+        Wireguard *w = WIREGUARD(netdev);
 
         explicit_bzero_safe(w->private_key, WG_KEY_LEN);
         free(w->private_key_file);
@@ -1124,13 +1076,9 @@ static int wireguard_peer_verify(WireguardPeer *peer) {
 }
 
 static int wireguard_verify(NetDev *netdev, const char *filename) {
-        Wireguard *w;
+        Wireguard *w = WIREGUARD(netdev);
         int r;
 
-        assert(netdev);
-        w = WIREGUARD(netdev);
-        assert(w);
-
         r = wireguard_read_key_file(w->private_key_file, w->private_key);
         if (r < 0)
                 return log_netdev_error_errno(netdev, r,
index 816e10640093607f496dc00476cb28c5ae895efd..904e40fe81c552f972e57ee784a6e6c1e8fa1972 100644 (file)
 #include "wlan.h"
 
 static void wlan_done(NetDev *netdev) {
-        WLan *w;
-
-        assert(netdev);
-
-        w = WLAN(netdev);
-
-        assert(w);
+        WLan *w = WLAN(netdev);
 
         w->wiphy_name = mfree(w->wiphy_name);
 }
 
 static void wlan_init(NetDev *netdev) {
-        WLan *w;
-
-        assert(netdev);
-
-        w = WLAN(netdev);
-
-        assert(w);
+        WLan *w = WLAN(netdev);
 
         w->wiphy_index = UINT32_MAX;
         w->wds = -1;
 }
 
 static int wlan_get_wiphy(NetDev *netdev, Wiphy **ret) {
-        WLan *w;
-
-        assert(netdev);
-
-        w = WLAN(netdev);
-
-        assert(w);
+        WLan *w = WLAN(netdev);
 
         if (w->wiphy_name)
                 return wiphy_get_by_name(netdev->manager, w->wiphy_name, ret);
@@ -56,17 +38,10 @@ static int wlan_is_ready_to_create(NetDev *netdev, Link *link) {
 }
 
 static int wlan_fill_message(NetDev *netdev, sd_netlink_message *m) {
+        WLan *w = WLAN(netdev);
         Wiphy *wiphy;
-        WLan *w;
         int r;
 
-        assert(netdev);
-        assert(m);
-
-        w = WLAN(netdev);
-
-        assert(w);
-
         r = wlan_get_wiphy(netdev, &wiphy);
         if (r < 0)
                 return r;
@@ -145,15 +120,10 @@ static int wlan_create(NetDev *netdev) {
 }
 
 static int wlan_verify(NetDev *netdev, const char *filename) {
-        WLan *w;
+        WLan *w = WLAN(netdev);
 
-        assert(netdev);
         assert(filename);
 
-        w = WLAN(netdev);
-
-        assert(w);
-
         if (w->iftype == NL80211_IFTYPE_UNSPECIFIED)
                 return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
                                                 "%s: WLAN interface type is not specified, ignoring.",
@@ -179,7 +149,7 @@ int config_parse_wiphy(
                 void *data,
                 void *userdata) {
 
-        WLan *w = ASSERT_PTR(userdata);
+        WLan *w = WLAN(userdata);
         int r;
 
         assert(filename);
index a304283172298ac51aad88974c402e201df57547..905bfc0bdf03da6af3bd2bcb03c14f040e204915 100644 (file)
@@ -6,10 +6,9 @@
 #include "xfrm.h"
 
 static int xfrm_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *message) {
-        assert(netdev);
         assert(message);
 
-        Xfrm *x = ASSERT_PTR(XFRM(netdev));
+        Xfrm *x = XFRM(netdev);
         int r;
 
         assert(link || x->independent);
@@ -26,10 +25,9 @@ static int xfrm_fill_message_create(NetDev *netdev, Link *link, sd_netlink_messa
 }
 
 static int xfrm_verify(NetDev *netdev, const char *filename) {
-        assert(netdev);
         assert(filename);
 
-        Xfrm *x = ASSERT_PTR(XFRM(netdev));
+        Xfrm *x = XFRM(netdev);
 
         if (x->if_id == 0)
                 return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
index e0a8be6b544b0a79aa0689b1a93d539c8aa22c1a..94506c975de3d4ff88761892daebfd64b437d53f 100644 (file)
@@ -209,8 +209,6 @@ int network_verify(Network *network) {
                                 else
                                         continue;
 
-                                assert(m);
-
                                 if (m->mode == NETDEV_MACVLAN_MODE_PASSTHRU)
                                         network->link_local = ADDRESS_FAMILY_NO;
 
index 6cefd3a9bf52f2d206674bed94f276b5569642d2..023d81b5784287a87782ee26828b4d2461d7d54c 100644 (file)
@@ -889,15 +889,14 @@ static bool route_by_kernel(const Route *route) {
 }
 
 static void link_unmark_wireguard_routes(Link *link) {
-        Route *route, *existing;
-        Wireguard *w;
-
         assert(link);
 
-        w = WIREGUARD(link->netdev);
-        if (!w)
+        if (!link->netdev || link->netdev->kind != NETDEV_KIND_WIREGUARD)
                 return;
 
+        Route *route, *existing;
+        Wireguard *w = WIREGUARD(link->netdev);
+
         SET_FOREACH(route, w->routes)
                 if (route_get(NULL, link, route, &existing) >= 0)
                         route_unmark(existing);
@@ -1527,7 +1526,6 @@ static int link_request_static_route(Link *link, Route *route) {
 
 static int link_request_wireguard_routes(Link *link, bool only_ipv4) {
         NetDev *netdev;
-        Wireguard *w;
         Route *route;
         int r;
 
@@ -1539,9 +1537,7 @@ static int link_request_wireguard_routes(Link *link, bool only_ipv4) {
         if (netdev_get(link->manager, link->ifname, &netdev) < 0)
                 return 0;
 
-        w = WIREGUARD(netdev);
-        if (!w)
-                return 0;
+        Wireguard *w = WIREGUARD(netdev);
 
         SET_FOREACH(route, w->routes) {
                 if (only_ipv4 && route->family != AF_INET)