From: Zbigniew Jędrzejewski-Szmek Date: Sat, 16 Sep 2023 10:11:34 +0000 (+0200) Subject: network/netdev: use ASSERT_PTR() more, adjust indentation X-Git-Tag: v255-rc1~458^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=257cebb67a979b408f8d0814559717ae3a491812;p=thirdparty%2Fsystemd.git network/netdev: use ASSERT_PTR() more, adjust indentation --- diff --git a/src/network/netdev/bareudp.c b/src/network/netdev/bareudp.c index 24d3afb8771..539f8486e5c 100644 --- a/src/network/netdev/bareudp.c +++ b/src/network/netdev/bareudp.c @@ -21,15 +21,11 @@ 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) { - BareUDP *u; - int r; - assert(netdev); assert(m); - u = BAREUDP(netdev); - - assert(u); + BareUDP *u = ASSERT_PTR(BAREUDP(netdev)); + int r; r = sd_netlink_message_append_u16(m, IFLA_BAREUDP_ETHERTYPE, htobe16(u->iftype)); if (r < 0) @@ -43,14 +39,10 @@ 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) { - BareUDP *u; - assert(netdev); assert(filename); - u = BAREUDP(netdev); - - assert(u); + BareUDP *u = ASSERT_PTR(BAREUDP(netdev)); if (u->dest_port == 0) return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL), @@ -64,13 +56,9 @@ static int netdev_bare_udp_verify(NetDev *netdev, const char *filename) { } static void bare_udp_init(NetDev *netdev) { - BareUDP *u; - assert(netdev); - u = BAREUDP(netdev); - - assert(u); + BareUDP *u = ASSERT_PTR(BAREUDP(netdev)); u->iftype = _BARE_UDP_PROTOCOL_INVALID; } diff --git a/src/network/netdev/bond.c b/src/network/netdev/bond.c index 704a4c6b4c1..6bedf0cd3ea 100644 --- a/src/network/netdev/bond.c +++ b/src/network/netdev/bond.c @@ -57,16 +57,12 @@ 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) { - Bond *b; - int r; - assert(netdev); assert(!link); assert(m); - b = BOND(netdev); - - assert(b); + Bond *b = ASSERT_PTR(BOND(netdev)); + int r; if (b->mode != _NETDEV_BOND_MODE_INVALID) { r = sd_netlink_message_append_u8(m, IFLA_BOND_MODE, b->mode); @@ -237,14 +233,14 @@ int config_parse_arp_ip_target_address( void *data, void *userdata) { - Bond *b = userdata; - int r; - assert(filename); assert(lvalue); assert(rvalue); assert(data); + Bond *b = ASSERT_PTR(BOND(userdata)); + int r; + if (isempty(rvalue)) { b->arp_ip_targets = ordered_set_free(b->arp_ip_targets); return 0; @@ -382,23 +378,17 @@ int config_parse_ad_actor_system( } static void bond_done(NetDev *netdev) { - Bond *b; - assert(netdev); - b = BOND(netdev); - assert(b); + + Bond *b = ASSERT_PTR(BOND(netdev)); ordered_set_free(b->arp_ip_targets); } static void bond_init(NetDev *netdev) { - Bond *b; - assert(netdev); - b = BOND(netdev); - - assert(b); + Bond *b = ASSERT_PTR(BOND(netdev)); b->mode = _NETDEV_BOND_MODE_INVALID; b->xmit_hash_policy = _NETDEV_BOND_XMIT_HASH_POLICY_INVALID; diff --git a/src/network/netdev/bridge.c b/src/network/netdev/bridge.c index 3783139d158..19638a871f8 100644 --- a/src/network/netdev/bridge.c +++ b/src/network/netdev/bridge.c @@ -46,10 +46,10 @@ 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) { - Bridge *b; - int r; + assert(netdev); - assert_se(b = BRIDGE(netdev)); + Bridge *b = ASSERT_PTR(BRIDGE(netdev)); + int r; r = sd_netlink_message_open_container(req, IFLA_LINKINFO); if (r < 0) @@ -231,12 +231,8 @@ int config_parse_bridge_port_priority( prio); } -static void bridge_init(NetDev *n) { - Bridge *b; - - b = BRIDGE(n); - - assert(b); +static void bridge_init(NetDev *netdev) { + Bridge *b = ASSERT_PTR(BRIDGE(netdev)); b->mcast_querier = -1; b->mcast_snooping = -1; diff --git a/src/network/netdev/fou-tunnel.c b/src/network/netdev/fou-tunnel.c index 7baec1529f4..2786bf6bb88 100644 --- a/src/network/netdev/fou-tunnel.c +++ b/src/network/netdev/fou-tunnel.c @@ -24,12 +24,12 @@ 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) { - FouTunnel *t; + assert(netdev); + + FouTunnel *t = ASSERT_PTR(FOU(netdev)); uint8_t encap_type; int r; - assert_se(t = FOU(netdev)); - r = sd_netlink_message_append_u16(m, FOU_ATTR_PORT, htobe16(t->port)); if (r < 0) return r; @@ -225,14 +225,10 @@ int config_parse_fou_tunnel_address( } static int netdev_fou_tunnel_verify(NetDev *netdev, const char *filename) { - FouTunnel *t; - assert(netdev); assert(filename); - t = FOU(netdev); - - assert(t); + FouTunnel *t = ASSERT_PTR(FOU(netdev)); switch (t->fou_encap_type) { case NETDEV_FOO_OVER_UDP_ENCAP_DIRECT: diff --git a/src/network/netdev/geneve.c b/src/network/netdev/geneve.c index 83c73aff077..f5f325711cd 100644 --- a/src/network/netdev/geneve.c +++ b/src/network/netdev/geneve.c @@ -28,13 +28,11 @@ 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) { - Geneve *v; - int r; - assert(netdev); assert(m); - v = GENEVE(netdev); + Geneve *v = ASSERT_PTR(GENEVE(netdev)); + int r; if (v->id <= GENEVE_VID_MAX) { r = sd_netlink_message_append_u32(m, IFLA_GENEVE_ID, v->id); @@ -141,24 +139,26 @@ int config_parse_geneve_address( void *data, void *userdata) { - Geneve *v = userdata; - union in_addr_union *addr = data, buffer; - int r, f; - assert(filename); assert(lvalue); assert(rvalue); assert(data); + Geneve *v = ASSERT_PTR(userdata); + union in_addr_union *addr = data, buffer; + int r, f; + r = in_addr_from_string_auto(rvalue, &f, &buffer); if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, "geneve '%s' address is invalid, ignoring assignment: %s", lvalue, rvalue); + log_syntax(unit, LOG_WARNING, filename, line, r, + "geneve '%s' address is invalid, ignoring assignment: %s", lvalue, rvalue); return 0; } r = in_addr_is_multicast(f, &buffer); if (r > 0) { - log_syntax(unit, LOG_WARNING, filename, line, 0, "geneve invalid multicast '%s' address, ignoring assignment: %s", lvalue, rvalue); + log_syntax(unit, LOG_WARNING, filename, line, 0, + "geneve invalid multicast '%s' address, ignoring assignment: %s", lvalue, rvalue); return 0; } @@ -180,15 +180,15 @@ int config_parse_geneve_flow_label( void *data, void *userdata) { - Geneve *v = userdata; - uint32_t f; - int r; - assert(filename); assert(lvalue); assert(rvalue); assert(data); + Geneve *v = ASSERT_PTR(userdata); + uint32_t f; + int r; + r = safe_atou32(rvalue, &f); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse Geneve flow label '%s'.", rvalue); @@ -237,28 +237,22 @@ int config_parse_geneve_ttl( } static int netdev_geneve_verify(NetDev *netdev, const char *filename) { - Geneve *v = GENEVE(netdev); - assert(netdev); - assert(v); assert(filename); + Geneve *v = ASSERT_PTR(GENEVE(netdev)); + if (v->id > GENEVE_VID_MAX) return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL), "%s: Geneve without valid VNI (or Virtual Network Identifier) configured. Ignoring.", filename); - return 0; } static void geneve_init(NetDev *netdev) { - Geneve *v; - assert(netdev); - v = GENEVE(netdev); - - assert(v); + Geneve *v = ASSERT_PTR(GENEVE(netdev)); v->id = GENEVE_VID_MAX + 1; v->geneve_df = _NETDEV_GENEVE_DF_INVALID; diff --git a/src/network/netdev/macsec.c b/src/network/netdev/macsec.c index 0da3dd4bd22..6469a97b29e 100644 --- a/src/network/netdev/macsec.c +++ b/src/network/netdev/macsec.c @@ -356,13 +356,11 @@ static int netdev_macsec_configure_receive_association(NetDev *netdev, ReceiveAs } static int macsec_receive_channel_handler(sd_netlink *rtnl, sd_netlink_message *m, ReceiveChannel *c) { - NetDev *netdev; - int r; - assert(c); assert(c->macsec); - netdev = NETDEV(c->macsec); + NetDev *netdev = ASSERT_PTR(NETDEV(c->macsec)); + int r; assert(netdev->state != _NETDEV_STATE_INVALID); @@ -474,15 +472,13 @@ 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)); TransmitAssociation *a; ReceiveChannel *c; - MACsec *s; int r; - assert(netdev); - s = MACSEC(netdev); - assert(s); - ORDERED_HASHMAP_FOREACH(a, s->transmit_associations_by_section) { r = netdev_macsec_configure_transmit_association(netdev, a); if (r < 0) @@ -499,15 +495,11 @@ static int netdev_macsec_configure(NetDev *netdev, Link *link) { } static int netdev_macsec_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { - MACsec *v; - int r; - assert(netdev); assert(m); - v = MACSEC(netdev); - - assert(v); + MACsec *v = ASSERT_PTR(MACSEC(netdev)); + int r; if (v->port > 0) { r = sd_netlink_message_append_u16(m, IFLA_MACSEC_PORT, v->port); @@ -540,19 +532,19 @@ int config_parse_macsec_port( void *data, void *userdata) { - _cleanup_(macsec_receive_association_free_or_set_invalidp) ReceiveAssociation *b = NULL; - _cleanup_(macsec_receive_channel_free_or_set_invalidp) ReceiveChannel *c = NULL; - MACsec *s = userdata; - uint16_t port; - void *dest; - int r; - assert(filename); assert(section); assert(lvalue); assert(rvalue); assert(data); + MACsec *s = ASSERT_PTR(userdata); + _cleanup_(macsec_receive_association_free_or_set_invalidp) ReceiveAssociation *b = NULL; + _cleanup_(macsec_receive_channel_free_or_set_invalidp) ReceiveChannel *c = NULL; + uint16_t port; + void *dest; + int r; + /* This parses port used to make Secure Channel Identifier (SCI) */ if (streq(section, "MACsec")) @@ -601,17 +593,17 @@ int config_parse_macsec_hw_address( void *data, void *userdata) { - _cleanup_(macsec_receive_association_free_or_set_invalidp) ReceiveAssociation *b = NULL; - _cleanup_(macsec_receive_channel_free_or_set_invalidp) ReceiveChannel *c = NULL; - MACsec *s = userdata; - int r; - assert(filename); assert(section); assert(lvalue); assert(rvalue); assert(data); + MACsec *s = ASSERT_PTR(userdata); + _cleanup_(macsec_receive_association_free_or_set_invalidp) ReceiveAssociation *b = NULL; + _cleanup_(macsec_receive_channel_free_or_set_invalidp) ReceiveChannel *c = NULL; + int r; + if (streq(section, "MACsecReceiveChannel")) r = macsec_receive_channel_new_static(s, filename, section_line, &c); else @@ -645,18 +637,18 @@ int config_parse_macsec_packet_number( void *data, void *userdata) { - _cleanup_(macsec_transmit_association_free_or_set_invalidp) TransmitAssociation *a = NULL; - _cleanup_(macsec_receive_association_free_or_set_invalidp) ReceiveAssociation *b = NULL; - MACsec *s = userdata; - uint32_t val, *dest; - int r; - assert(filename); assert(section); assert(lvalue); assert(rvalue); assert(data); + MACsec *s = ASSERT_PTR(userdata); + _cleanup_(macsec_transmit_association_free_or_set_invalidp) TransmitAssociation *a = NULL; + _cleanup_(macsec_receive_association_free_or_set_invalidp) ReceiveAssociation *b = NULL; + uint32_t val, *dest; + int r; + if (streq(section, "MACsecTransmitAssociation")) r = macsec_transmit_association_new_static(s, filename, section_line, &a); else diff --git a/src/network/netdev/tunnel.c b/src/network/netdev/tunnel.c index ced04c77eca..a6985753d4b 100644 --- a/src/network/netdev/tunnel.c +++ b/src/network/netdev/tunnel.c @@ -207,11 +207,9 @@ static int netdev_ipip_sit_fill_message_create(NetDev *netdev, Link *link, sd_ne assert(m); if (netdev->kind == NETDEV_KIND_IPIP) - t = IPIP(netdev); + t = ASSERT_PTR(IPIP(netdev)); else - t = SIT(netdev); - - assert(t); + t = ASSERT_PTR(SIT(netdev)); if (t->external) { r = sd_netlink_message_append_flag(m, IFLA_IPTUN_COLLECT_METADATA); @@ -268,8 +266,8 @@ static int netdev_ipip_sit_fill_message_create(NetDev *netdev, Link *link, sd_ne if (r < 0) return r; - /* u16 is deliberate here, even though we're passing a netmask that can never be >128. The kernel is - * expecting to receive the prefixlen as a u16. + /* u16 is deliberate here, even though we're passing a netmask that can never be + * >128. The kernel is expecting to receive the prefixlen as a u16. */ r = sd_netlink_message_append_u16(m, IFLA_IPTUN_6RD_PREFIXLEN, t->sixrd_prefixlen); if (r < 0) @@ -304,20 +302,18 @@ static int netdev_gre_erspan_fill_message_create(NetDev *netdev, Link *link, sd_ switch (netdev->kind) { case NETDEV_KIND_GRE: - t = GRE(netdev); + t = ASSERT_PTR(GRE(netdev)); break; case NETDEV_KIND_ERSPAN: - t = ERSPAN(netdev); + t = ASSERT_PTR(ERSPAN(netdev)); break; case NETDEV_KIND_GRETAP: - t = GRETAP(netdev); + t = ASSERT_PTR(GRETAP(netdev)); break; default: assert_not_reached(); } - assert(t); - if (t->external) { r = sd_netlink_message_append_flag(m, IFLA_GRE_COLLECT_METADATA); if (r < 0) @@ -441,10 +437,8 @@ static int netdev_gre_erspan_fill_message_create(NetDev *netdev, Link *link, sd_ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { union in_addr_union local; - uint32_t ikey = 0; - uint32_t okey = 0; - uint16_t iflags = 0; - uint16_t oflags = 0; + uint32_t ikey = 0, okey = 0; + uint16_t iflags = 0, oflags = 0; Tunnel *t; int r; @@ -452,11 +446,9 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netl assert(m); if (netdev->kind == NETDEV_KIND_IP6GRE) - t = IP6GRE(netdev); + t = ASSERT_PTR(IP6GRE(netdev)); else - t = IP6GRETAP(netdev); - - assert(t); + t = ASSERT_PTR(IP6GRETAP(netdev)); if (t->external) { r = sd_netlink_message_append_flag(m, IFLA_GRE_COLLECT_METADATA); @@ -544,11 +536,9 @@ static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink assert(m); if (netdev->kind == NETDEV_KIND_VTI) - t = VTI(netdev); + t = ASSERT_PTR(VTI(netdev)); else - t = VTI6(netdev); - - assert(t); + t = ASSERT_PTR(VTI6(netdev)); if (link || t->assign_to_loopback) { r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link ? link->ifindex : LOOPBACK_IFINDEX); @@ -587,17 +577,13 @@ static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink } static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { - union in_addr_union local; - uint8_t proto; - Tunnel *t; - int r; - assert(netdev); assert(m); - t = IP6TNL(netdev); - - assert(t); + union in_addr_union local; + uint8_t proto; + Tunnel *t = ASSERT_PTR(IP6TNL(netdev)); + int r; switch (t->ip6tnl_mode) { case NETDEV_IP6_TNL_MODE_IP6IP6: @@ -673,13 +659,9 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netl } static int netdev_tunnel_is_ready_to_create(NetDev *netdev, Link *link) { - Tunnel *t; - assert(netdev); - t = TUNNEL(netdev); - - assert(t); + Tunnel *t = ASSERT_PTR(TUNNEL(netdev)); if (t->independent) return true; @@ -688,14 +670,10 @@ static int netdev_tunnel_is_ready_to_create(NetDev *netdev, Link *link) { } static int netdev_tunnel_verify(NetDev *netdev, const char *filename) { - Tunnel *t; - assert(netdev); assert(filename); - t = TUNNEL(netdev); - - assert(t); + Tunnel *t = ASSERT_PTR(TUNNEL(netdev)); if (netdev->kind == NETDEV_KIND_IP6TNL && t->ip6tnl_mode == _NETDEV_IP6_TNL_MODE_INVALID) @@ -1149,13 +1127,7 @@ int config_parse_erspan_hwid( } static void netdev_tunnel_init(NetDev *netdev) { - Tunnel *t; - - assert(netdev); - - t = TUNNEL(netdev); - - assert(t); + Tunnel *t = ASSERT_PTR(TUNNEL(netdev)); t->local_type = _NETDEV_LOCAL_ADDRESS_TYPE_INVALID; t->pmtudisc = -1; diff --git a/src/network/netdev/xfrm.c b/src/network/netdev/xfrm.c index a961d8fef24..a3042831722 100644 --- a/src/network/netdev/xfrm.c +++ b/src/network/netdev/xfrm.c @@ -6,15 +6,12 @@ #include "xfrm.h" static int xfrm_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *message) { - Xfrm *x; - int r; - assert(netdev); assert(message); - x = XFRM(netdev); + Xfrm *x = ASSERT_PTR(XFRM(netdev)); + int r; - assert(x); assert(link || x->independent); r = sd_netlink_message_append_u32(message, IFLA_XFRM_LINK, link ? link->ifindex : LOOPBACK_IFINDEX); @@ -29,19 +26,14 @@ static int xfrm_fill_message_create(NetDev *netdev, Link *link, sd_netlink_messa } static int xfrm_verify(NetDev *netdev, const char *filename) { - Xfrm *x; - assert(netdev); assert(filename); - x = XFRM(netdev); - - assert(x); + Xfrm *x = ASSERT_PTR(XFRM(netdev)); if (x->if_id == 0) return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL), "%s: Xfrm interface ID cannot be zero.", filename); - return 0; }