]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: rename NetworkConfigSection -> ConfigSection
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 27 Dec 2021 01:34:24 +0000 (10:34 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 19 Jan 2022 05:57:59 +0000 (14:57 +0900)
And move it and relevant functions to conf-parser.[ch].

36 files changed:
src/network/netdev/l2tp-tunnel.c
src/network/netdev/l2tp-tunnel.h
src/network/netdev/macsec.c
src/network/netdev/macsec.h
src/network/netdev/wireguard.c
src/network/netdev/wireguard.h
src/network/networkd-address-label.c
src/network/networkd-address-label.h
src/network/networkd-address.c
src/network/networkd-address.h
src/network/networkd-bridge-fdb.c
src/network/networkd-bridge-fdb.h
src/network/networkd-bridge-mdb.c
src/network/networkd-bridge-mdb.h
src/network/networkd-dhcp-server-static-lease.c
src/network/networkd-dhcp-server-static-lease.h
src/network/networkd-neighbor.c
src/network/networkd-neighbor.h
src/network/networkd-nexthop.c
src/network/networkd-nexthop.h
src/network/networkd-radv.c
src/network/networkd-radv.h
src/network/networkd-route.c
src/network/networkd-route.h
src/network/networkd-routing-policy-rule.c
src/network/networkd-routing-policy-rule.h
src/network/networkd-sriov.c
src/network/networkd-sriov.h
src/network/networkd-util.c
src/network/networkd-util.h
src/network/tc/qdisc.c
src/network/tc/qdisc.h
src/network/tc/tclass.c
src/network/tc/tclass.h
src/shared/conf-parser.c
src/shared/conf-parser.h

index d870a11e008d82c6a0e47e788d36bf91978fa9c6..419541ebdf3ddda5108abf391211bb91bf43960f 100644 (file)
@@ -46,15 +46,15 @@ static L2tpSession* l2tp_session_free(L2tpSession *s) {
         if (s->tunnel && s->section)
                 ordered_hashmap_remove(s->tunnel->sessions_by_section, s->section);
 
-        network_config_section_free(s->section);
+        config_section_free(s->section);
         free(s->name);
         return mfree(s);
 }
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(L2tpSession, l2tp_session_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(L2tpSession, l2tp_session_free);
 
 static int l2tp_session_new_static(L2tpTunnel *t, const char *filename, unsigned section_line, L2tpSession **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(l2tp_session_freep) L2tpSession *s = NULL;
         int r;
 
@@ -63,7 +63,7 @@ static int l2tp_session_new_static(L2tpTunnel *t, const char *filename, unsigned
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -83,7 +83,7 @@ static int l2tp_session_new_static(L2tpTunnel *t, const char *filename, unsigned
                 .section = TAKE_PTR(n),
         };
 
-        r = ordered_hashmap_ensure_put(&t->sessions_by_section, &network_config_hash_ops, s->section, s);
+        r = ordered_hashmap_ensure_put(&t->sessions_by_section, &config_section_hash_ops, s->section, s);
         if (r < 0)
                 return r;
 
index a884d2100f076e5b4ef0a4c9f08189c194423269..236b78ce4b9678f75d79c8ace0b272480c6f6104 100644 (file)
@@ -34,7 +34,7 @@ typedef struct L2tpTunnel L2tpTunnel;
 
 typedef struct L2tpSession {
         L2tpTunnel *tunnel;
-        NetworkConfigSection *section;
+        ConfigSection *section;
 
         char *name;
 
index ebb8c9c7dcb8bb499293fde775819e50fc572374..a049ade6ba9e68ef924e2f4965c83e4e890972ef 100644 (file)
@@ -43,16 +43,16 @@ static ReceiveAssociation* macsec_receive_association_free(ReceiveAssociation *c
         if (c->macsec && c->section)
                 ordered_hashmap_remove(c->macsec->receive_associations_by_section, c->section);
 
-        network_config_section_free(c->section);
+        config_section_free(c->section);
         security_association_clear(&c->sa);
 
         return mfree(c);
 }
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(ReceiveAssociation, macsec_receive_association_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(ReceiveAssociation, macsec_receive_association_free);
 
 static int macsec_receive_association_new_static(MACsec *s, const char *filename, unsigned section_line, ReceiveAssociation **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(macsec_receive_association_freep) ReceiveAssociation *c = NULL;
         int r;
 
@@ -61,7 +61,7 @@ static int macsec_receive_association_new_static(MACsec *s, const char *filename
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -82,7 +82,7 @@ static int macsec_receive_association_new_static(MACsec *s, const char *filename
 
         security_association_init(&c->sa);
 
-        r = ordered_hashmap_ensure_put(&s->receive_associations_by_section, &network_config_hash_ops, c->section, c);
+        r = ordered_hashmap_ensure_put(&s->receive_associations_by_section, &config_section_hash_ops, c->section, c);
         if (r < 0)
                 return r;
 
@@ -103,12 +103,12 @@ static ReceiveChannel* macsec_receive_channel_free(ReceiveChannel *c) {
                         ordered_hashmap_remove(c->macsec->receive_channels_by_section, c->section);
         }
 
-        network_config_section_free(c->section);
+        config_section_free(c->section);
 
         return mfree(c);
 }
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(ReceiveChannel, macsec_receive_channel_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(ReceiveChannel, macsec_receive_channel_free);
 
 static int macsec_receive_channel_new(MACsec *s, uint64_t sci, ReceiveChannel **ret) {
         ReceiveChannel *c;
@@ -129,7 +129,7 @@ static int macsec_receive_channel_new(MACsec *s, uint64_t sci, ReceiveChannel **
 }
 
 static int macsec_receive_channel_new_static(MACsec *s, const char *filename, unsigned section_line, ReceiveChannel **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(macsec_receive_channel_freep) ReceiveChannel *c = NULL;
         int r;
 
@@ -138,7 +138,7 @@ static int macsec_receive_channel_new_static(MACsec *s, const char *filename, un
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -154,7 +154,7 @@ static int macsec_receive_channel_new_static(MACsec *s, const char *filename, un
 
         c->section = TAKE_PTR(n);
 
-        r = ordered_hashmap_ensure_put(&s->receive_channels_by_section, &network_config_hash_ops, c->section, c);
+        r = ordered_hashmap_ensure_put(&s->receive_channels_by_section, &config_section_hash_ops, c->section, c);
         if (r < 0)
                 return r;
 
@@ -170,16 +170,16 @@ static TransmitAssociation* macsec_transmit_association_free(TransmitAssociation
         if (a->macsec && a->section)
                 ordered_hashmap_remove(a->macsec->transmit_associations_by_section, a->section);
 
-        network_config_section_free(a->section);
+        config_section_free(a->section);
         security_association_clear(&a->sa);
 
         return mfree(a);
 }
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(TransmitAssociation, macsec_transmit_association_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(TransmitAssociation, macsec_transmit_association_free);
 
 static int macsec_transmit_association_new_static(MACsec *s, const char *filename, unsigned section_line, TransmitAssociation **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(macsec_transmit_association_freep) TransmitAssociation *a = NULL;
         int r;
 
@@ -188,7 +188,7 @@ static int macsec_transmit_association_new_static(MACsec *s, const char *filenam
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -209,7 +209,7 @@ static int macsec_transmit_association_new_static(MACsec *s, const char *filenam
 
         security_association_init(&a->sa);
 
-        r = ordered_hashmap_ensure_put(&s->transmit_associations_by_section, &network_config_hash_ops, a->section, a);
+        r = ordered_hashmap_ensure_put(&s->transmit_associations_by_section, &config_section_hash_ops, a->section, a);
         if (r < 0)
                 return r;
 
index 4d88e49514657f9573e37158552d7a533031802e..17bb1ca3fbe5799a1bc82fbb3247548b55d577ef 100644 (file)
@@ -39,14 +39,14 @@ typedef struct SecurityAssociation {
 
 typedef struct TransmitAssociation {
         MACsec *macsec;
-        NetworkConfigSection *section;
+        ConfigSection *section;
 
         SecurityAssociation sa;
 } TransmitAssociation;
 
 typedef struct ReceiveAssociation {
         MACsec *macsec;
-        NetworkConfigSection *section;
+        ConfigSection *section;
 
         MACsecSCI sci;
         SecurityAssociation sa;
@@ -54,7 +54,7 @@ typedef struct ReceiveAssociation {
 
 typedef struct ReceiveChannel {
         MACsec *macsec;
-        NetworkConfigSection *section;
+        ConfigSection *section;
 
         MACsecSCI sci;
         ReceiveAssociation *rxsa[MACSEC_MAX_ASSOCIATION_NUMBER];
index 88f668753a50b9d6978e46d842422ed787374455..431b5ec045437279d49ed4bf587bfeb5162526c6 100644 (file)
@@ -47,7 +47,7 @@ static WireguardPeer* wireguard_peer_free(WireguardPeer *peer) {
                         hashmap_remove(peer->wireguard->peers_by_section, peer->section);
         }
 
-        network_config_section_free(peer->section);
+        config_section_free(peer->section);
 
         while ((mask = peer->ipmasks)) {
                 LIST_REMOVE(ipmasks, peer->ipmasks, mask);
@@ -65,10 +65,10 @@ static WireguardPeer* wireguard_peer_free(WireguardPeer *peer) {
         return mfree(peer);
 }
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(WireguardPeer, wireguard_peer_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(WireguardPeer, wireguard_peer_free);
 
 static int wireguard_peer_new_static(Wireguard *w, const char *filename, unsigned section_line, WireguardPeer **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(wireguard_peer_freep) WireguardPeer *peer = NULL;
         int r;
 
@@ -77,7 +77,7 @@ static int wireguard_peer_new_static(Wireguard *w, const char *filename, unsigne
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -99,7 +99,7 @@ static int wireguard_peer_new_static(Wireguard *w, const char *filename, unsigne
 
         LIST_PREPEND(peers, w->peers, peer);
 
-        r = hashmap_ensure_put(&w->peers_by_section, &network_config_hash_ops, peer->section, peer);
+        r = hashmap_ensure_put(&w->peers_by_section, &config_section_hash_ops, peer->section, peer);
         if (r < 0)
                 return r;
 
index 29bacdc77109e170cd22b1f3bdb1630d14917625..09dca88bbf0803bf29ccfed5fd57b931b6ceac59 100644 (file)
@@ -24,7 +24,7 @@ typedef struct WireguardIPmask {
 
 typedef struct WireguardPeer {
         Wireguard *wireguard;
-        NetworkConfigSection *section;
+        ConfigSection *section;
 
         uint8_t public_key[WG_KEY_LEN];
         uint8_t preshared_key[WG_KEY_LEN];
index 6f911b805f0841f27993960b2ecdda785bb9119c..506238f3919036eac1aeb093e89c950ddc1d862b 100644 (file)
@@ -21,14 +21,14 @@ AddressLabel *address_label_free(AddressLabel *label) {
                 hashmap_remove(label->network->address_labels_by_section, label->section);
         }
 
-        network_config_section_free(label->section);
+        config_section_free(label->section);
         return mfree(label);
 }
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(AddressLabel, address_label_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(AddressLabel, address_label_free);
 
 static int address_label_new_static(Network *network, const char *filename, unsigned section_line, AddressLabel **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(address_label_freep) AddressLabel *label = NULL;
         int r;
 
@@ -37,7 +37,7 @@ static int address_label_new_static(Network *network, const char *filename, unsi
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -57,7 +57,7 @@ static int address_label_new_static(Network *network, const char *filename, unsi
                 .label = UINT32_MAX,
         };
 
-        r = hashmap_ensure_put(&network->address_labels_by_section, &network_config_hash_ops, label->section, label);
+        r = hashmap_ensure_put(&network->address_labels_by_section, &config_section_hash_ops, label->section, label);
         if (r < 0)
                 return r;
 
index 0f975454d9939208d22b742e0e69951227b9596f..582dd05b8809705f080ba34ae279eb267c1dee78 100644 (file)
@@ -13,7 +13,7 @@ typedef struct Request Request;
 
 typedef struct AddressLabel {
         Network *network;
-        NetworkConfigSection *section;
+        ConfigSection *section;
 
         uint32_t label;
         struct in6_addr prefix;
index 7df743efb55768e40c127542388fc3a013698e97..ff80f185ceac50dd25d377414e90bbe5a34e77b6 100644 (file)
@@ -77,7 +77,7 @@ int address_new(Address **ret) {
 }
 
 static int address_new_static(Network *network, const char *filename, unsigned section_line, Address **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(address_freep) Address *address = NULL;
         int r;
 
@@ -86,7 +86,7 @@ static int address_new_static(Network *network, const char *filename, unsigned s
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -107,7 +107,7 @@ static int address_new_static(Network *network, const char *filename, unsigned s
         address->section = TAKE_PTR(n);
         address->source = NETWORK_CONFIG_SOURCE_STATIC;
 
-        r = ordered_hashmap_ensure_put(&network->addresses_by_section, &network_config_hash_ops, address->section, address);
+        r = ordered_hashmap_ensure_put(&network->addresses_by_section, &config_section_hash_ops, address->section, address);
         if (r < 0)
                 return r;
 
@@ -134,7 +134,7 @@ Address *address_free(Address *address) {
 
         sd_ipv4acd_unref(address->acd);
 
-        network_config_section_free(address->section);
+        config_section_free(address->section);
         free(address->label);
         return mfree(address);
 }
index 41c4ce6fa4d59f02812deb906857c412c5cca8af..c1e5b3ce3a762a846e2231f60cc124a86f37830b 100644 (file)
@@ -22,7 +22,7 @@ typedef int (*address_ready_callback_t)(Address *address);
 struct Address {
         Link *link;
         Network *network;
-        NetworkConfigSection *section;
+        ConfigSection *section;
         NetworkConfigSource source;
         NetworkConfigState state;
         union in_addr_union provider; /* DHCP server or router address */
@@ -72,7 +72,7 @@ int address_dup(const Address *src, Address **ret);
 bool address_is_ready(const Address *a);
 void address_set_broadcast(Address *a);
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(Address, address_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(Address, address_free);
 
 int link_drop_addresses(Link *link);
 int link_drop_foreign_addresses(Link *link);
index a0024f62d48ae823ef03b9e411cd78a903f0ec09..c1e2977d4dfb32e679a09fa7509b88d2d727a11a 100644 (file)
@@ -32,13 +32,13 @@ BridgeFDB *bridge_fdb_free(BridgeFDB *fdb) {
                 hashmap_remove(fdb->network->bridge_fdb_entries_by_section, fdb->section);
         }
 
-        network_config_section_free(fdb->section);
+        config_section_free(fdb->section);
 
         free(fdb->outgoing_ifname);
         return mfree(fdb);
 }
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(BridgeFDB, bridge_fdb_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(BridgeFDB, bridge_fdb_free);
 
 /* create a new FDB entry or get an existing one. */
 static int bridge_fdb_new_static(
@@ -47,7 +47,7 @@ static int bridge_fdb_new_static(
                 unsigned section_line,
                 BridgeFDB **ret) {
 
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(bridge_fdb_freep) BridgeFDB *fdb = NULL;
         int r;
 
@@ -56,7 +56,7 @@ static int bridge_fdb_new_static(
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -83,7 +83,7 @@ static int bridge_fdb_new_static(
                 .ntf_flags = NEIGHBOR_CACHE_ENTRY_FLAGS_SELF,
         };
 
-        r = hashmap_ensure_put(&network->bridge_fdb_entries_by_section, &network_config_hash_ops, fdb->section, fdb);
+        r = hashmap_ensure_put(&network->bridge_fdb_entries_by_section, &config_section_hash_ops, fdb->section, fdb);
         if (r < 0)
                 return r;
 
index fae7da5bbb2c72bf66f1b742ab17bc2e50d4ae11..b1098760d2d9e3ad522b3f90ab7ca44597896959 100644 (file)
@@ -27,7 +27,7 @@ typedef enum NeighborCacheEntryFlags {
 
 typedef struct BridgeFDB {
         Network *network;
-        NetworkConfigSection *section;
+        ConfigSection *section;
 
         uint32_t vni;
 
index 10025a97aeb85169b26e84ca44d205b13d29ab24..d155090ad1012eaa02980bc85b95c0eda5eb6dce 100644 (file)
@@ -24,12 +24,12 @@ BridgeMDB *bridge_mdb_free(BridgeMDB *mdb) {
                 hashmap_remove(mdb->network->bridge_mdb_entries_by_section, mdb->section);
         }
 
-        network_config_section_free(mdb->section);
+        config_section_free(mdb->section);
 
         return mfree(mdb);
 }
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(BridgeMDB, bridge_mdb_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(BridgeMDB, bridge_mdb_free);
 
 /* create a new MDB entry or get an existing one. */
 static int bridge_mdb_new_static(
@@ -38,7 +38,7 @@ static int bridge_mdb_new_static(
                 unsigned section_line,
                 BridgeMDB **ret) {
 
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(bridge_mdb_freep) BridgeMDB *mdb = NULL;
         int r;
 
@@ -47,7 +47,7 @@ static int bridge_mdb_new_static(
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -72,7 +72,7 @@ static int bridge_mdb_new_static(
                 .section = TAKE_PTR(n),
         };
 
-        r = hashmap_ensure_put(&network->bridge_mdb_entries_by_section, &network_config_hash_ops, mdb->section, mdb);
+        r = hashmap_ensure_put(&network->bridge_mdb_entries_by_section, &config_section_hash_ops, mdb->section, mdb);
         if (r < 0)
                 return r;
 
index 9ca262e0ce9acaa664649d34328efc71066d671c..ce91e3f5725d691a5a5505318bcf37e6921de459 100644 (file)
@@ -13,7 +13,7 @@ typedef struct Request Request;
 
 typedef struct BridgeMDB {
         Network *network;
-        NetworkConfigSection *section;
+        ConfigSection *section;
 
         int family;
         union in_addr_union group_addr;
index 6acd838e2b790f24e54aca8fc5ec09dc4f4ea832..38e8c7e889b86d4bcd788321177f208a2f82e845 100644 (file)
@@ -7,7 +7,7 @@
 #include "networkd-network.h"
 #include "networkd-util.h"
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(DHCPStaticLease, dhcp_static_lease_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(DHCPStaticLease, dhcp_static_lease_free);
 
 DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *static_lease) {
         if (!static_lease)
@@ -16,7 +16,7 @@ DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *static_lease) {
         if (static_lease->network && static_lease->section)
                 hashmap_remove(static_lease->network->dhcp_static_leases_by_section, static_lease->section);
 
-        network_config_section_free(static_lease->section);
+        config_section_free(static_lease->section);
         free(static_lease->client_id);
         return mfree(static_lease);
 }
@@ -35,7 +35,7 @@ static int dhcp_static_lease_new(DHCPStaticLease **ret) {
 }
 
 static int lease_new_static(Network *network, const char *filename, unsigned section_line, DHCPStaticLease **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(dhcp_static_lease_freep) DHCPStaticLease *static_lease = NULL;
         int r;
 
@@ -44,7 +44,7 @@ static int lease_new_static(Network *network, const char *filename, unsigned sec
         assert(section_line > 0);
         assert(ret);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -60,7 +60,7 @@ static int lease_new_static(Network *network, const char *filename, unsigned sec
 
         static_lease->network = network;
         static_lease->section = TAKE_PTR(n);
-        r = hashmap_ensure_put(&network->dhcp_static_leases_by_section, &network_config_hash_ops, static_lease->section, static_lease);
+        r = hashmap_ensure_put(&network->dhcp_static_leases_by_section, &config_section_hash_ops, static_lease->section, static_lease);
         if (r < 0)
                 return r;
 
index c2a9ad6bb12aa2e418b639368a4906465a94b906..9b8e78b90d817cc27482e404d91760fa220c92a5 100644 (file)
@@ -8,11 +8,11 @@
 #include "in-addr-util.h"
 
 typedef struct Network Network;
-typedef struct NetworkConfigSection NetworkConfigSection;
+typedef struct ConfigSection ConfigSection;
 
 typedef struct DHCPStaticLease {
         Network *network;
-        NetworkConfigSection *section;
+        ConfigSection *section;
 
         struct in_addr address;
         uint8_t *client_id;
index 26b7385497087045d8729121c953b438e6da386b..4aab290bf803e7c2a575260ea342c280015c2696 100644 (file)
@@ -19,7 +19,7 @@ Neighbor *neighbor_free(Neighbor *neighbor) {
                 hashmap_remove(neighbor->network->neighbors_by_section, neighbor->section);
         }
 
-        network_config_section_free(neighbor->section);
+        config_section_free(neighbor->section);
 
         if (neighbor->link)
                 set_remove(neighbor->link->neighbors, neighbor);
@@ -27,10 +27,10 @@ Neighbor *neighbor_free(Neighbor *neighbor) {
         return mfree(neighbor);
 }
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(Neighbor, neighbor_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(Neighbor, neighbor_free);
 
 static int neighbor_new_static(Network *network, const char *filename, unsigned section_line, Neighbor **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(neighbor_freep) Neighbor *neighbor = NULL;
         int r;
 
@@ -39,7 +39,7 @@ static int neighbor_new_static(Network *network, const char *filename, unsigned
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -60,7 +60,7 @@ static int neighbor_new_static(Network *network, const char *filename, unsigned
                 .source = NETWORK_CONFIG_SOURCE_STATIC,
         };
 
-        r = hashmap_ensure_put(&network->neighbors_by_section, &network_config_hash_ops, neighbor->section, neighbor);
+        r = hashmap_ensure_put(&network->neighbors_by_section, &config_section_hash_ops, neighbor->section, neighbor);
         if (r < 0)
                 return r;
 
index e9e18541107ada2ce6710f2f043ebda1fe669f34..f31f58a4d4ea4e6059c14257dbfe1059e3fcf610 100644 (file)
@@ -18,7 +18,7 @@ typedef struct Request Request;
 typedef struct Neighbor {
         Network *network;
         Link *link;
-        NetworkConfigSection *section;
+        ConfigSection *section;
         NetworkConfigSource source;
         NetworkConfigState state;
 
index b829aaab90ade59b6c2f0e2a6f13153363db09c3..e9e5d08557bd6a7047d73b90d7d4b0f2f4f15a81 100644 (file)
@@ -27,7 +27,7 @@ NextHop *nexthop_free(NextHop *nexthop) {
                 hashmap_remove(nexthop->network->nexthops_by_section, nexthop->section);
         }
 
-        network_config_section_free(nexthop->section);
+        config_section_free(nexthop->section);
 
         if (nexthop->link) {
                 set_remove(nexthop->link->nexthops, nexthop);
@@ -48,7 +48,7 @@ NextHop *nexthop_free(NextHop *nexthop) {
         return mfree(nexthop);
 }
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(NextHop, nexthop_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(NextHop, nexthop_free);
 
 static int nexthop_new(NextHop **ret) {
         _cleanup_(nexthop_freep) NextHop *nexthop = NULL;
@@ -68,7 +68,7 @@ static int nexthop_new(NextHop **ret) {
 }
 
 static int nexthop_new_static(Network *network, const char *filename, unsigned section_line, NextHop **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(nexthop_freep) NextHop *nexthop = NULL;
         int r;
 
@@ -77,7 +77,7 @@ static int nexthop_new_static(Network *network, const char *filename, unsigned s
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -96,7 +96,7 @@ static int nexthop_new_static(Network *network, const char *filename, unsigned s
         nexthop->section = TAKE_PTR(n);
         nexthop->source = NETWORK_CONFIG_SOURCE_STATIC;
 
-        r = hashmap_ensure_put(&network->nexthops_by_section, &network_config_hash_ops, nexthop->section, nexthop);
+        r = hashmap_ensure_put(&network->nexthops_by_section, &config_section_hash_ops, nexthop->section, nexthop);
         if (r < 0)
                 return r;
 
index 7a8920238c0bc64556097571072506b24719d809..01b29ae560294454c87b175ea7e41ef8d6c2f036 100644 (file)
@@ -22,7 +22,7 @@ typedef struct NextHop {
         Network *network;
         Manager *manager;
         Link *link;
-        NetworkConfigSection *section;
+        ConfigSection *section;
         NetworkConfigSource source;
         NetworkConfigState state;
 
index 59b0922a4c4e4a169bcce0f907d27cf7509e334c..0c5eebc8157a68de93e783aed372b8a3040e81bc 100644 (file)
@@ -69,16 +69,16 @@ Prefix *prefix_free(Prefix *prefix) {
                 hashmap_remove(prefix->network->prefixes_by_section, prefix->section);
         }
 
-        network_config_section_free(prefix->section);
+        config_section_free(prefix->section);
         set_free(prefix->tokens);
 
         return mfree(prefix);
 }
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(Prefix, prefix_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(Prefix, prefix_free);
 
 static int prefix_new_static(Network *network, const char *filename, unsigned section_line, Prefix **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(prefix_freep) Prefix *prefix = NULL;
         int r;
 
@@ -87,7 +87,7 @@ static int prefix_new_static(Network *network, const char *filename, unsigned se
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -111,7 +111,7 @@ static int prefix_new_static(Network *network, const char *filename, unsigned se
                 .address_auto_configuration = true,
         };
 
-        r = hashmap_ensure_put(&network->prefixes_by_section, &network_config_hash_ops, prefix->section, prefix);
+        r = hashmap_ensure_put(&network->prefixes_by_section, &config_section_hash_ops, prefix->section, prefix);
         if (r < 0)
                 return r;
 
@@ -128,15 +128,15 @@ RoutePrefix *route_prefix_free(RoutePrefix *prefix) {
                 hashmap_remove(prefix->network->route_prefixes_by_section, prefix->section);
         }
 
-        network_config_section_free(prefix->section);
+        config_section_free(prefix->section);
 
         return mfree(prefix);
 }
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(RoutePrefix, route_prefix_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(RoutePrefix, route_prefix_free);
 
 static int route_prefix_new_static(Network *network, const char *filename, unsigned section_line, RoutePrefix **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(route_prefix_freep) RoutePrefix *prefix = NULL;
         int r;
 
@@ -145,7 +145,7 @@ static int route_prefix_new_static(Network *network, const char *filename, unsig
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -166,7 +166,7 @@ static int route_prefix_new_static(Network *network, const char *filename, unsig
                 .lifetime = RADV_DEFAULT_VALID_LIFETIME_USEC,
         };
 
-        r = hashmap_ensure_put(&network->route_prefixes_by_section, &network_config_hash_ops, prefix->section, prefix);
+        r = hashmap_ensure_put(&network->route_prefixes_by_section, &config_section_hash_ops, prefix->section, prefix);
         if (r < 0)
                 return r;
 
index 392c00b37d16d0410a94ccdf8b7370b9716b5bb4..952fa8ae58e173c4a02ebadd9fa53a0c245e90c1 100644 (file)
@@ -29,7 +29,7 @@ typedef enum RADVPrefixDelegation {
 
 typedef struct Prefix {
         Network *network;
-        NetworkConfigSection *section;
+        ConfigSection *section;
 
         struct in6_addr prefix;
         uint8_t prefixlen;
@@ -46,7 +46,7 @@ typedef struct Prefix {
 
 typedef struct RoutePrefix {
         Network *network;
-        NetworkConfigSection *section;
+        ConfigSection *section;
 
         struct in6_addr prefix;
         uint8_t prefixlen;
index 00e64978d45ba7ba36b21b0ec5ce91c023a4e776..03021362b6cb7851d8a95e406bdfc8bd041db904 100644 (file)
@@ -47,7 +47,7 @@ int route_new(Route **ret) {
 }
 
 static int route_new_static(Network *network, const char *filename, unsigned section_line, Route **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(route_freep) Route *route = NULL;
         int r;
 
@@ -56,7 +56,7 @@ static int route_new_static(Network *network, const char *filename, unsigned sec
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -78,7 +78,7 @@ static int route_new_static(Network *network, const char *filename, unsigned sec
         route->section = TAKE_PTR(n);
         route->source = NETWORK_CONFIG_SOURCE_STATIC;
 
-        r = hashmap_ensure_put(&network->routes_by_section, &network_config_hash_ops, route->section, route);
+        r = hashmap_ensure_put(&network->routes_by_section, &config_section_hash_ops, route->section, route);
         if (r < 0)
                 return r;
 
@@ -95,7 +95,7 @@ Route *route_free(Route *route) {
                 hashmap_remove(route->network->routes_by_section, route->section);
         }
 
-        network_config_section_free(route->section);
+        config_section_free(route->section);
 
         if (route->link)
                 set_remove(route->link->routes, route);
index e3e22a59853ce95e5c5c7800318dd3b7f81f8905..3471008fee7145bb565c74cfa14f0ea57d8dd7e7 100644 (file)
@@ -19,7 +19,7 @@ typedef struct Route {
         Link *link;
         Manager *manager;
         Network *network;
-        NetworkConfigSection *section;
+        ConfigSection *section;
         NetworkConfigSource source;
         NetworkConfigState state;
         union in_addr_union provider; /* DHCP server or router address */
@@ -74,7 +74,7 @@ extern const struct hash_ops route_hash_ops;
 
 int route_new(Route **ret);
 Route *route_free(Route *route);
-DEFINE_NETWORK_SECTION_FUNCTIONS(Route, route_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(Route, route_free);
 int route_dup(const Route *src, Route **ret);
 
 int route_configure_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg);
index a2e72a7d7c7b3a4cdc6cb4c4874f9ee17f8f0a40..1f3dfa53b0ccdc8ef516f5a29f3f74b2491c302b 100644 (file)
@@ -54,14 +54,14 @@ RoutingPolicyRule *routing_policy_rule_free(RoutingPolicyRule *rule) {
         if (rule->manager)
                 set_remove(rule->manager->rules, rule);
 
-        network_config_section_free(rule->section);
+        config_section_free(rule->section);
         free(rule->iif);
         free(rule->oif);
 
         return mfree(rule);
 }
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(RoutingPolicyRule, routing_policy_rule_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(RoutingPolicyRule, routing_policy_rule_free);
 
 static int routing_policy_rule_new(RoutingPolicyRule **ret) {
         RoutingPolicyRule *rule;
@@ -86,7 +86,7 @@ static int routing_policy_rule_new(RoutingPolicyRule **ret) {
 
 static int routing_policy_rule_new_static(Network *network, const char *filename, unsigned section_line, RoutingPolicyRule **ret) {
         _cleanup_(routing_policy_rule_freep) RoutingPolicyRule *rule = NULL;
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         int r;
 
         assert(network);
@@ -94,7 +94,7 @@ static int routing_policy_rule_new_static(Network *network, const char *filename
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -113,7 +113,7 @@ static int routing_policy_rule_new_static(Network *network, const char *filename
         rule->source = NETWORK_CONFIG_SOURCE_STATIC;
         rule->protocol = RTPROT_STATIC;
 
-        r = hashmap_ensure_put(&network->rules_by_section, &network_config_hash_ops, rule->section, rule);
+        r = hashmap_ensure_put(&network->rules_by_section, &config_section_hash_ops, rule->section, rule);
         if (r < 0)
                 return r;
 
index f52943bd2e6d11434b7dfad113c953c32e3b2eee..1ab147caae7b37b99ce35600c759465d832f6c71 100644 (file)
@@ -17,7 +17,7 @@ typedef struct Request Request;
 typedef struct RoutingPolicyRule {
         Manager *manager;
         Network *network;
-        NetworkConfigSection *section;
+        ConfigSection *section;
         NetworkConfigSource source;
         NetworkConfigState state;
 
index 1443d40d4ce9dffc3be5e2be8f68602194edb2db..79e607b3dab4618edd0f8b51dceee4c9709b65c3 100644 (file)
@@ -33,7 +33,7 @@ static int sr_iov_new(SRIOV **ret) {
 }
 
 static int sr_iov_new_static(Network *network, const char *filename, unsigned section_line, SRIOV **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(sr_iov_freep) SRIOV *sr_iov = NULL;
         SRIOV *existing = NULL;
         int r;
@@ -43,7 +43,7 @@ static int sr_iov_new_static(Network *network, const char *filename, unsigned se
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -60,7 +60,7 @@ static int sr_iov_new_static(Network *network, const char *filename, unsigned se
         sr_iov->network = network;
         sr_iov->section = TAKE_PTR(n);
 
-        r = ordered_hashmap_ensure_put(&network->sr_iov_by_section, &network_config_hash_ops, sr_iov->section, sr_iov);
+        r = ordered_hashmap_ensure_put(&network->sr_iov_by_section, &config_section_hash_ops, sr_iov->section, sr_iov);
         if (r < 0)
                 return r;
 
@@ -75,7 +75,7 @@ SRIOV *sr_iov_free(SRIOV *sr_iov) {
         if (sr_iov->network && sr_iov->section)
                 ordered_hashmap_remove(sr_iov->network->sr_iov_by_section, sr_iov->section);
 
-        network_config_section_free(sr_iov->section);
+        config_section_free(sr_iov->section);
 
         return mfree(sr_iov);
 }
index be4430a9a049c0893f41857a27922c477515e30a..270a82b233d9347043b529d7df8cabd3b1368191 100644 (file)
@@ -19,7 +19,7 @@ typedef enum SRIOVLinkState {
 } SRIOVLinkState;
 
 typedef struct SRIOV {
-        NetworkConfigSection *section;
+        ConfigSection *section;
         Network *network;
 
         uint32_t vf;   /* 0 - 2147483646 */
@@ -37,7 +37,7 @@ SRIOV *sr_iov_free(SRIOV *sr_iov);
 int link_configure_sr_iov(Link *link);
 int network_drop_invalid_sr_iov(Network *network);
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(SRIOV, sr_iov_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(SRIOV, sr_iov_free);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_uint32);
 CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_boolean);
index ac6f1680ca4b1fecd5de9ccf43878e1cb32b2537..1c0987bc3370c1049359e039171c2984face2681 100644 (file)
@@ -243,50 +243,6 @@ int config_parse_mud_url(
         return free_and_replace(*url, unescaped);
 }
 
-static void network_config_hash_func(const NetworkConfigSection *c, struct siphash *state) {
-        siphash24_compress_string(c->filename, state);
-        siphash24_compress(&c->line, sizeof(c->line), state);
-}
-
-static int network_config_compare_func(const NetworkConfigSection *x, const NetworkConfigSection *y) {
-        int r;
-
-        r = strcmp(x->filename, y->filename);
-        if (r != 0)
-                return r;
-
-        return CMP(x->line, y->line);
-}
-
-DEFINE_HASH_OPS(network_config_hash_ops, NetworkConfigSection, network_config_hash_func, network_config_compare_func);
-
-int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s) {
-        NetworkConfigSection *cs;
-
-        cs = malloc0(offsetof(NetworkConfigSection, filename) + strlen(filename) + 1);
-        if (!cs)
-                return -ENOMEM;
-
-        strcpy(cs->filename, filename);
-        cs->line = line;
-
-        *s = TAKE_PTR(cs);
-
-        return 0;
-}
-
-unsigned hashmap_find_free_section_line(Hashmap *hashmap) {
-        NetworkConfigSection *cs;
-        unsigned n = 0;
-        void *entry;
-
-        HASHMAP_FOREACH_KEY(entry, cs, hashmap)
-                if (n < cs->line)
-                        n = cs->line;
-
-        return n + 1;
-}
-
 int log_link_message_full_errno(Link *link, sd_netlink_message *m, int level, int err, const char *msg) {
         const char *err_msg = NULL;
 
index d94243855e712515321cdcdd6faa4290ae62212e..0a627588aa2e5c617dcad43f846098ab4fd23c1c 100644 (file)
 
 typedef struct Link Link;
 
-typedef struct NetworkConfigSection {
-        unsigned line;
-        bool invalid;
-        char filename[];
-} NetworkConfigSection;
-
 typedef enum NetworkConfigSource {
         NETWORK_CONFIG_SOURCE_FOREIGN, /* configured by kernel */
         NETWORK_CONFIG_SOURCE_STATIC,
@@ -141,37 +135,6 @@ AddressFamily dhcp_deprecated_address_family_from_string(const char *s) _pure_;
 const char *dhcp_lease_server_type_to_string(sd_dhcp_lease_server_type_t t) _const_;
 sd_dhcp_lease_server_type_t dhcp_lease_server_type_from_string(const char *s) _pure_;
 
-static inline NetworkConfigSection* network_config_section_free(NetworkConfigSection *cs) {
-        return mfree(cs);
-}
-DEFINE_TRIVIAL_CLEANUP_FUNC(NetworkConfigSection*, network_config_section_free);
-
-int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s);
-extern const struct hash_ops network_config_hash_ops;
-unsigned hashmap_find_free_section_line(Hashmap *hashmap);
-
-static inline bool section_is_invalid(NetworkConfigSection *section) {
-        /* If this returns false, then it does _not_ mean the section is valid. */
-
-        if (!section)
-                return false;
-
-        return section->invalid;
-}
-
-#define DEFINE_NETWORK_SECTION_FUNCTIONS(type, free_func)               \
-        static inline type* free_func##_or_set_invalid(type *p) {       \
-                assert(p);                                              \
-                                                                        \
-                if (p->section)                                         \
-                        p->section->invalid = true;                     \
-                else                                                    \
-                        free_func(p);                                   \
-                return NULL;                                            \
-        }                                                               \
-        DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func);                  \
-        DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func##_or_set_invalid);
-
 int log_link_message_full_errno(Link *link, sd_netlink_message *m, int level, int err, const char *msg);
 #define log_link_message_error_errno(link, m, err, msg)   log_link_message_full_errno(link, m, LOG_ERR, err, msg)
 #define log_link_message_warning_errno(link, m, err, msg) log_link_message_full_errno(link, m, LOG_WARNING, err, msg)
index 995df2fc866a048cb29c42790d3593195b3c0932..803c999855b106d4e711d582cf35edfe316e60de 100644 (file)
@@ -77,7 +77,7 @@ static int qdisc_new(QDiscKind kind, QDisc **ret) {
 }
 
 int qdisc_new_static(QDiscKind kind, Network *network, const char *filename, unsigned section_line, QDisc **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(qdisc_freep) QDisc *qdisc = NULL;
         TrafficControl *existing;
         QDisc *q = NULL;
@@ -88,7 +88,7 @@ int qdisc_new_static(QDiscKind kind, Network *network, const char *filename, uns
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -126,7 +126,7 @@ int qdisc_new_static(QDiscKind kind, Network *network, const char *filename, uns
         qdisc->network = network;
         qdisc->section = TAKE_PTR(n);
 
-        r = ordered_hashmap_ensure_put(&network->tc_by_section, &network_config_hash_ops, qdisc->section, TC(qdisc));
+        r = ordered_hashmap_ensure_put(&network->tc_by_section, &config_section_hash_ops, qdisc->section, TC(qdisc));
         if (r < 0)
                 return r;
 
@@ -141,7 +141,7 @@ QDisc* qdisc_free(QDisc *qdisc) {
         if (qdisc->network && qdisc->section)
                 ordered_hashmap_remove(qdisc->network->tc_by_section, qdisc->section);
 
-        network_config_section_free(qdisc->section);
+        config_section_free(qdisc->section);
 
         free(qdisc->tca_kind);
         return mfree(qdisc);
index bf2df146a7ea0c465c631a10d123298a2c440f13..e37c4806e32cb2ea31b0c65089e42342bea68b68 100644 (file)
@@ -37,7 +37,7 @@ typedef enum QDiscKind {
 typedef struct QDisc {
         TrafficControl meta;
 
-        NetworkConfigSection *section;
+        ConfigSection *section;
         Network *network;
 
         int family;
@@ -80,7 +80,7 @@ int qdisc_new_static(QDiscKind kind, Network *network, const char *filename, uns
 int qdisc_configure(Link *link, QDisc *qdisc);
 int qdisc_section_verify(QDisc *qdisc, bool *has_root, bool *has_clsact);
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(QDisc, qdisc_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(QDisc, qdisc_free);
 
 DEFINE_TC_CAST(QDISC, QDisc);
 
index 10bffd65c6262014c4e98d295079552f1691e895..6a36ac1c1cd6c1d8ce3a92e5e46f1f72a9f1e106 100644 (file)
@@ -45,7 +45,7 @@ static int tclass_new(TClassKind kind, TClass **ret) {
 }
 
 int tclass_new_static(TClassKind kind, Network *network, const char *filename, unsigned section_line, TClass **ret) {
-        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(config_section_freep) ConfigSection *n = NULL;
         _cleanup_(tclass_freep) TClass *tclass = NULL;
         TrafficControl *existing;
         int r;
@@ -55,7 +55,7 @@ int tclass_new_static(TClassKind kind, Network *network, const char *filename, u
         assert(filename);
         assert(section_line > 0);
 
-        r = network_config_section_new(filename, section_line, &n);
+        r = config_section_new(filename, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -82,7 +82,7 @@ int tclass_new_static(TClassKind kind, Network *network, const char *filename, u
         tclass->network = network;
         tclass->section = TAKE_PTR(n);
 
-        r = ordered_hashmap_ensure_put(&network->tc_by_section, &network_config_hash_ops, tclass->section, tclass);
+        r = ordered_hashmap_ensure_put(&network->tc_by_section, &config_section_hash_ops, tclass->section, tclass);
         if (r < 0)
                 return r;
 
@@ -97,7 +97,7 @@ TClass* tclass_free(TClass *tclass) {
         if (tclass->network && tclass->section)
                 ordered_hashmap_remove(tclass->network->tc_by_section, tclass->section);
 
-        network_config_section_free(tclass->section);
+        config_section_free(tclass->section);
 
         return mfree(tclass);
 }
index fc91789f30007b15140d56ff9eda577e0fb1f6fe..5f8016c187258c868f2db2c9310c8e770378b126 100644 (file)
@@ -19,7 +19,7 @@ typedef enum TClassKind {
 typedef struct TClass {
         TrafficControl meta;
 
-        NetworkConfigSection *section;
+        ConfigSection *section;
         Network *network;
 
         uint32_t classid;
@@ -59,7 +59,7 @@ int tclass_new_static(TClassKind kind, Network *network, const char *filename, u
 int tclass_configure(Link *link, TClass *tclass);
 int tclass_section_verify(TClass *tclass);
 
-DEFINE_NETWORK_SECTION_FUNCTIONS(TClass, tclass_free);
+DEFINE_SECTION_CLEANUP_FUNCTIONS(TClass, tclass_free);
 
 DEFINE_TC_CAST(TCLASS, TClass);
 
index 1e1967d7ea232dd0ef270d60618af728992d1adb..64e67fb6f5754a7f58c91d7fdc1a95e8d4da003f 100644 (file)
@@ -573,6 +573,50 @@ int config_parse_many(
         return config_parse_many_files(conf_files, files, sections, lookup, table, flags, userdata, ret_stats_by_path);
 }
 
+static void config_section_hash_func(const ConfigSection *c, struct siphash *state) {
+        siphash24_compress_string(c->filename, state);
+        siphash24_compress(&c->line, sizeof(c->line), state);
+}
+
+static int config_section_compare_func(const ConfigSection *x, const ConfigSection *y) {
+        int r;
+
+        r = strcmp(x->filename, y->filename);
+        if (r != 0)
+                return r;
+
+        return CMP(x->line, y->line);
+}
+
+DEFINE_HASH_OPS(config_section_hash_ops, ConfigSection, config_section_hash_func, config_section_compare_func);
+
+int config_section_new(const char *filename, unsigned line, ConfigSection **s) {
+        ConfigSection *cs;
+
+        cs = malloc0(offsetof(ConfigSection, filename) + strlen(filename) + 1);
+        if (!cs)
+                return -ENOMEM;
+
+        strcpy(cs->filename, filename);
+        cs->line = line;
+
+        *s = TAKE_PTR(cs);
+
+        return 0;
+}
+
+unsigned hashmap_find_free_section_line(Hashmap *hashmap) {
+        ConfigSection *cs;
+        unsigned n = 0;
+        void *entry;
+
+        HASHMAP_FOREACH_KEY(entry, cs, hashmap)
+                if (n < cs->line)
+                        n = cs->line;
+
+        return n + 1;
+}
+
 #define DEFINE_PARSER(type, vartype, conv_func)                         \
         DEFINE_CONFIG_PARSE_PTR(config_parse_##type, conv_func, vartype, "Failed to parse " #type " value")
 
index d6866655327612bf66acc71caf1796b9a3f955d3..1e03f93bce14aacfd77b028c778e3682afb75337 100644 (file)
@@ -114,6 +114,43 @@ int config_parse_many(
                 void *userdata,
                 Hashmap **ret_stats_by_path);   /* possibly NULL */
 
+typedef struct ConfigSection {
+        unsigned line;
+        bool invalid;
+        char filename[];
+} ConfigSection;
+
+static inline ConfigSection* config_section_free(ConfigSection *cs) {
+        return mfree(cs);
+}
+DEFINE_TRIVIAL_CLEANUP_FUNC(ConfigSection*, config_section_free);
+
+int config_section_new(const char *filename, unsigned line, ConfigSection **s);
+extern const struct hash_ops config_section_hash_ops;
+unsigned hashmap_find_free_section_line(Hashmap *hashmap);
+
+static inline bool section_is_invalid(ConfigSection *section) {
+        /* If this returns false, then it does _not_ mean the section is valid. */
+
+        if (!section)
+                return false;
+
+        return section->invalid;
+}
+
+#define DEFINE_SECTION_CLEANUP_FUNCTIONS(type, free_func)               \
+        static inline type* free_func##_or_set_invalid(type *p) {       \
+                assert(p);                                              \
+                                                                        \
+                if (p->section)                                         \
+                        p->section->invalid = true;                     \
+                else                                                    \
+                        free_func(p);                                   \
+                return NULL;                                            \
+        }                                                               \
+        DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func);                  \
+        DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func##_or_set_invalid);
+
 CONFIG_PARSER_PROTOTYPE(config_parse_int);
 CONFIG_PARSER_PROTOTYPE(config_parse_unsigned);
 CONFIG_PARSER_PROTOTYPE(config_parse_long);