summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-09-24 15:25:20 +0200
committerTom Gundersen <teg@jklm.no>2015-10-11 15:04:16 +0200
commit91b5f997316ddc77d26f9a7a5e24c335484586bd (patch)
tree7606f8766ebefe32a39329c89713074c0bdfd5a8 /src
parent054f0db48775d566e4f55feb7cda0f721a9eb485 (diff)
networkd: make address_{establish,release}() static
No need to expose these functions, but rather call them from address_{add,drop}.
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-address.c103
-rw-r--r--src/network/networkd-address.h5
-rw-r--r--src/network/networkd-dhcp4.c14
-rw-r--r--src/network/networkd-ipv4ll.c4
-rw-r--r--src/network/networkd-link.c4
-rw-r--r--src/network/networkd-link.h4
-rw-r--r--src/network/networkd-manager.c5
-rw-r--r--src/network/networkd-route.c2
-rw-r--r--src/network/networkd-route.h2
9 files changed, 76 insertions, 67 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 0414ced48a..48715972b6 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -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;
diff --git a/src/network/networkd-address.h b/src/network/networkd-address.h
index 0d575de131..22ac5e95c1 100644
--- a/src/network/networkd-address.h
+++ b/src/network/networkd-address.h
@@ -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);
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
index 0b7c016280..5d9bfcea7c 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -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);
}
}
diff --git a/src/network/networkd-ipv4ll.c b/src/network/networkd-ipv4ll.c
index 75d82de516..01ee9f9f4a 100644
--- a/src/network/networkd-ipv4ll.c
+++ b/src/network/networkd-ipv4ll.c
@@ -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);
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index eb03d72907..78853c8cca 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -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;
diff --git a/src/network/networkd-link.h b/src/network/networkd-link.h
index aaa6aaf178..b81bae3830 100644
--- a/src/network/networkd-link.h
+++ b/src/network/networkd-link.h
@@ -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);
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 19527b6509..07e47b668c 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -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);
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
index 28ce126849..1c8302ffaa 100644
--- a/src/network/networkd-route.c
+++ b/src/network/networkd-route.c
@@ -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;
diff --git a/src/network/networkd-route.h b/src/network/networkd-route.h
index b7e5bfb057..e3ed1be866 100644
--- a/src/network/networkd-route.h
+++ b/src/network/networkd-route.h
@@ -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)