]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: make address_{establish,release}() static
authorTom Gundersen <teg@jklm.no>
Thu, 24 Sep 2015 13:25:20 +0000 (15:25 +0200)
committerTom Gundersen <teg@jklm.no>
Sun, 11 Oct 2015 13:04:16 +0000 (15:04 +0200)
No need to expose these functions, but rather call them from address_{add,drop}.

src/network/networkd-address.c
src/network/networkd-address.h
src/network/networkd-dhcp4.c
src/network/networkd-ipv4ll.c
src/network/networkd-link.c
src/network/networkd-link.h
src/network/networkd-manager.c
src/network/networkd-route.c
src/network/networkd-route.h

index 0414ced48a7a7148eb073653599f56375018103c..48715972b6e18b7c2092a4445973a60cb5e4a705 100644 (file)
@@ -198,6 +198,33 @@ bool address_equal(Address *a1, Address *a2) {
         return address_compare_func(a1, a2) == 0;
 }
 
+static int address_establish(Address *address, Link *link) {
+        bool masq;
+        int r;
+
+        assert(address);
+        assert(link);
+
+        masq = link->network &&
+                link->network->ip_masquerade &&
+                address->family == AF_INET &&
+                address->scope < RT_SCOPE_LINK;
+
+        /* Add firewall entry if this is requested */
+        if (address->ip_masquerade_done != masq) {
+                union in_addr_union masked = address->in_addr;
+                in_addr_mask(address->family, &masked, address->prefixlen);
+
+                r = fw_add_masquerade(masq, AF_INET, 0, &masked, address->prefixlen, NULL, NULL, 0);
+                if (r < 0)
+                        log_link_warning_errno(link, r, "Could not enable IP masquerading: %m");
+
+                address->ip_masquerade_done = masq;
+        }
+
+        return 0;
+}
+
 int address_add(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret) {
         _cleanup_address_free_ Address *address = NULL;
         int r;
@@ -224,81 +251,67 @@ int address_add(Link *link, int family, const union in_addr_union *in_addr, unsi
 
         address->link = link;
 
+        r = address_establish(address, link);
+        if (r < 0)
+                return r;
+
         *ret = address;
         address = NULL;
 
         return 0;
 }
 
-int address_get(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret) {
-        Address address = {}, *existing;
-
-        assert(link);
-        assert(in_addr);
-        assert(ret);
-
-        address.family = family;
-        address.in_addr = *in_addr;
-        address.prefixlen = prefixlen;
-
-        existing = set_get(link->addresses, &address);
-        if (!existing)
-                return -ENOENT;
-
-        *ret = existing;
-
-        return 0;
-}
-
-int address_establish(Address *address, Link *link) {
-        bool masq;
+static int address_release(Address *address, Link *link) {
         int r;
 
         assert(address);
         assert(link);
 
-        masq = link->network &&
-                link->network->ip_masquerade &&
-                address->family == AF_INET &&
-                address->scope < RT_SCOPE_LINK;
-
-        /* Add firewall entry if this is requested */
-        if (address->ip_masquerade_done != masq) {
+        /* Remove masquerading firewall entry if it was added */
+        if (address->ip_masquerade_done) {
                 union in_addr_union masked = address->in_addr;
                 in_addr_mask(address->family, &masked, address->prefixlen);
 
-                r = fw_add_masquerade(masq, AF_INET, 0, &masked, address->prefixlen, NULL, NULL, 0);
+                r = fw_add_masquerade(false, AF_INET, 0, &masked, address->prefixlen, NULL, NULL, 0);
                 if (r < 0)
-                        log_link_warning_errno(link, r, "Could not enable IP masquerading: %m");
+                        log_link_warning_errno(link, r, "Failed to disable IP masquerading: %m");
 
-                address->ip_masquerade_done = masq;
+                address->ip_masquerade_done = false;
         }
 
         return 0;
 }
 
-int address_release(Address *address, Link *link) {
-        int r;
-
+int address_drop(Address *address) {
         assert(address);
+
+        address_release(address, address->link);
+        address_free(address);
+
+        return 0;
+}
+
+int address_get(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret) {
+        Address address = {}, *existing;
+
         assert(link);
+        assert(in_addr);
+        assert(ret);
 
-        /* Remove masquerading firewall entry if it was added */
-        if (address->ip_masquerade_done) {
-                union in_addr_union masked = address->in_addr;
-                in_addr_mask(address->family, &masked, address->prefixlen);
+        address.family = family;
+        address.in_addr = *in_addr;
+        address.prefixlen = prefixlen;
 
-                r = fw_add_masquerade(false, AF_INET, 0, &masked, address->prefixlen, NULL, NULL, 0);
-                if (r < 0)
-                        log_link_warning_errno(link, r, "Failed to disable IP masquerading: %m");
+        existing = set_get(link->addresses, &address);
+        if (!existing)
+                return -ENOENT;
 
-                address->ip_masquerade_done = false;
-        }
+        *ret = existing;
 
         return 0;
 }
 
-int address_drop(Address *address, Link *link,
+int address_remove(Address *address, Link *link,
                  sd_netlink_message_handler_t callback) {
         _cleanup_netlink_message_unref_ sd_netlink_message *req = NULL;
         int r;
index 0d575de131b2b6612848f36673b10ad6b349141b..22ac5e95c1b7c5643b193589a41f356ad966eb9e 100644 (file)
@@ -62,11 +62,10 @@ int address_new(Address **ret);
 void address_free(Address *address);
 int address_add(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret);
 int address_get(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret);
+int address_drop(Address *address);
 int address_configure(Address *address, Link *link, sd_netlink_message_handler_t callback);
 int address_update(Address *address, Link *link, sd_netlink_message_handler_t callback);
-int address_drop(Address *address, Link *link, sd_netlink_message_handler_t callback);
-int address_establish(Address *address, Link *link);
-int address_release(Address *address, Link *link);
+int address_remove(Address *address, Link *link, sd_netlink_message_handler_t callback);
 bool address_equal(Address *a1, Address *a2);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(Address*, address_free);
index 0b7c016280f0e2efba0a3c40a30545b68340e727..5d9bfcea7c9f70dc0bd625b5acac12972a8f490b 100644 (file)
@@ -169,8 +169,8 @@ static int dhcp_lease_lost(Link *link) {
                                         route->dst_addr.in = routes[i].dst_addr;
                                         route->dst_prefixlen = routes[i].dst_prefixlen;
 
-                                        route_drop(route, link,
-                                                   &link_route_drop_handler);
+                                        route_remove(route, link,
+                                                   &link_route_remove_handler);
                                 }
                         }
                 }
@@ -190,8 +190,8 @@ static int dhcp_lease_lost(Link *link) {
                                 route_gw->dst_prefixlen = 32;
                                 route_gw->scope = RT_SCOPE_LINK;
 
-                                route_drop(route_gw, link,
-                                           &link_route_drop_handler);
+                                route_remove(route_gw, link,
+                                           &link_route_remove_handler);
                         }
 
                         r = route_new(&route, RTPROT_UNSPEC);
@@ -199,8 +199,8 @@ static int dhcp_lease_lost(Link *link) {
                                 route->family = AF_INET;
                                 route->in_addr.in = gateway;
 
-                                route_drop(route, link,
-                                           &link_route_drop_handler);
+                                route_remove(route, link,
+                                           &link_route_remove_handler);
                         }
                 }
 
@@ -214,7 +214,7 @@ static int dhcp_lease_lost(Link *link) {
                         address->in_addr.in = addr;
                         address->prefixlen = prefixlen;
 
-                        address_drop(address, link, &link_address_drop_handler);
+                        address_remove(address, link, &link_address_remove_handler);
                 }
         }
 
index 75d82de516526804d60d08d0321860fa4ae9b6d0..01ee9f9f4ad60cedca06c3d93d5abe92bb8f3295 100644 (file)
@@ -53,7 +53,7 @@ static int ipv4ll_address_lost(Link *link) {
         address->prefixlen = 16;
         address->scope = RT_SCOPE_LINK;
 
-        address_drop(address, link, &link_address_drop_handler);
+        address_remove(address, link, &link_address_remove_handler);
 
         r = route_new(&route, RTPROT_UNSPEC);
         if (r < 0) {
@@ -65,7 +65,7 @@ static int ipv4ll_address_lost(Link *link) {
         route->scope = RT_SCOPE_LINK;
         route->metrics = IPV4LL_ROUTE_METRIC;
 
-        route_drop(route, link, &link_route_drop_handler);
+        route_remove(route, link, &link_route_remove_handler);
 
         link_client_handler(link);
 
index eb03d729079cb2aa49ebe0e4cf81868479641759..78853c8cca929fa110528ae62763252a5119ca3d 100644 (file)
@@ -586,7 +586,7 @@ static int link_enter_set_routes(Link *link) {
         return 0;
 }
 
-int link_route_drop_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
+int link_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
         _cleanup_link_unref_ Link *link = userdata;
         int r;
 
@@ -868,7 +868,7 @@ static int link_enter_set_addresses(Link *link) {
         return 0;
 }
 
-int link_address_drop_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
+int link_address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
         _cleanup_link_unref_ Link *link = userdata;
         int r;
 
index aaa6aaf178d128db00a49102fa1a59de945fd2e9..b81bae38309b14a5c8af3c01b1a04ec156858885 100644 (file)
@@ -120,8 +120,8 @@ int link_get(Manager *m, int ifindex, Link **ret);
 int link_add(Manager *manager, sd_netlink_message *message, Link **ret);
 void link_drop(Link *link);
 
-int link_address_drop_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
-int link_route_drop_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
+int link_address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
+int link_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
 
 void link_enter_failed(Link *link);
 int link_initialized(Link *link, struct udev_device *device);
index 19527b6509786032983f2c9baf1851dc8f14a205..07e47b668c1692df20804928189c17ee43d4fbdf 100644 (file)
@@ -416,8 +416,6 @@ int manager_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message,
                         address->flags = flags;
                         address->cinfo = cinfo;
 
-                        address_establish(address, link);
-
                         link_save(link);
                 }
 
@@ -427,8 +425,7 @@ int manager_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message,
 
                 if (address) {
                         log_link_debug(link, "Removing address: %s/%u (valid for %s)", buf, prefixlen, valid_str);
-                        address_release(address, link);
-                        address_free(address);
+                        address_drop(address);
                 } else
                         log_link_warning(link, "Removing non-existent address: %s/%u (valid for %s)", buf, prefixlen, valid_str);
 
index 28ce12684908330a41b6ba17972e8645d0db97ae..1c8302ffaa9360b7e047a221cdea3022f0debf14 100644 (file)
@@ -93,7 +93,7 @@ void route_free(Route *route) {
         free(route);
 }
 
-int route_drop(Route *route, Link *link,
+int route_remove(Route *route, Link *link,
                sd_netlink_message_handler_t callback) {
         _cleanup_netlink_message_unref_ sd_netlink_message *req = NULL;
         int r;
index b7e5bfb057d880f7a72668c40220136ec31e407a..e3ed1be86671497b76871363e48863b00ba2d5f2 100644 (file)
@@ -49,7 +49,7 @@ int route_new_static(Network *network, unsigned section, Route **ret);
 int route_new(Route **ret, unsigned char rtm_protocol);
 void route_free(Route *route);
 int route_configure(Route *route, Link *link, sd_netlink_message_handler_t callback);
-int route_drop(Route *route, Link *link, sd_netlink_message_handler_t callback);
+int route_remove(Route *route, Link *link, sd_netlink_message_handler_t callback);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(Route*, route_free);
 #define _cleanup_route_free_ _cleanup_(route_freep)