[systemd-commits] 2 commits - src/network

Tom Gundersen tomegun at kemper.freedesktop.org
Thu Dec 4 03:21:04 PST 2014


 src/network/networkctl.c            |  114 ++++--------------------------------
 src/network/networkd-link.c         |   18 ++---
 src/network/networkd-netdev-vxlan.c |   10 +--
 3 files changed, 29 insertions(+), 113 deletions(-)

New commits:
commit 00e8d83a5a6fce20443b53bc42066bc756d5caeb
Author: Tom Gundersen <teg at jklm.no>
Date:   Thu Dec 4 12:19:57 2014 +0100

    networkd: fix compile
    
    Rebase failure on my side.

diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index a4f8c59..7cffcb4 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -689,11 +689,11 @@ static int link_set_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
         _cleanup_link_unref_ Link *link = userdata;
         int r;
 
-        log_debug_link(link, "set link");
+        log_link_debug(link, "set link");
 
         r = sd_rtnl_message_get_errno(m);
         if (r < 0 && r != -EEXIST) {
-                log_struct_link(LOG_ERR, link,
+                log_link_struct(link, LOG_ERR,
                                 "MESSAGE=%-*s: could not join netdev: %s",
                                 IFNAMSIZ,
                                 link->ifname, strerror(-r),
@@ -836,20 +836,20 @@ static int link_set_bridge(Link *link) {
         r = sd_rtnl_message_new_link(link->manager->rtnl, &req,
                                      RTM_SETLINK, link->ifindex);
         if (r < 0) {
-                log_error_link(link, "Could not allocate RTM_SETLINK message");
+                log_link_error(link, "Could not allocate RTM_SETLINK message");
                 return r;
         }
 
         r = sd_rtnl_message_link_set_family(req, PF_BRIDGE);
         if (r < 0) {
-                log_error_link(link,
+                log_link_error(link,
                                "Could not set message family %s", strerror(-r));
                 return r;
         }
 
         r = sd_rtnl_message_open_container(req, IFLA_PROTINFO);
         if (r < 0) {
-                log_error_link(link,
+                log_link_error(link,
                                "Could not append IFLA_PROTINFO attribute: %s",
                                strerror(-r));
                 return r;
@@ -858,7 +858,7 @@ static int link_set_bridge(Link *link) {
         if(link->network->cost != 0) {
                 r = sd_rtnl_message_append_u32(req, IFLA_BRPORT_COST, link->network->cost);
                 if (r < 0) {
-                        log_error_link(link,
+                        log_link_error(link,
                                        "Could not append IFLA_BRPORT_COST attribute: %s",
                                        strerror(-r));
                         return r;
@@ -867,7 +867,7 @@ static int link_set_bridge(Link *link) {
 
         r = sd_rtnl_message_close_container(req);
         if (r < 0) {
-                log_error_link(link,
+                log_link_error(link,
                                "Could not append IFLA_LINKINFO attribute: %s",
                                strerror(-r));
                 return r;
@@ -875,7 +875,7 @@ static int link_set_bridge(Link *link) {
 
         r = sd_rtnl_call_async(link->manager->rtnl, req, link_set_handler, link, 0, NULL);
         if (r < 0) {
-                log_error_link(link,
+                log_link_error(link,
                                "Could not send rtnetlink message: %s",
                                strerror(-r));
                 return r;
@@ -1124,7 +1124,7 @@ static int link_joined(Link *link) {
         if(link->network->bridge) {
                 r = link_set_bridge(link);
                 if (r < 0) {
-                        log_error_link(link,
+                        log_link_error(link,
                                        "Could not set bridge message: %s",
                                        strerror(-r));
                 }
diff --git a/src/network/networkd-netdev-vxlan.c b/src/network/networkd-netdev-vxlan.c
index b19240e..d5128cb 100644
--- a/src/network/networkd-netdev-vxlan.c
+++ b/src/network/networkd-netdev-vxlan.c
@@ -95,7 +95,7 @@ static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_
 
         r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_RSC, v->route_short_circuit);
         if (r < 0) {
-                log_error_netdev(netdev,
+                log_netdev_error(netdev,
                                  "Could not append IFLA_VXLAN_RSC attribute: %s",
                                  strerror(-r));
                 return r;
@@ -103,7 +103,7 @@ static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_
 
         r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_PROXY, v->arp_proxy);
         if (r < 0) {
-                log_error_netdev(netdev,
+                log_netdev_error(netdev,
                                  "Could not append IFLA_VXLAN_PROXY attribute: %s",
                                  strerror(-r));
                 return r;
@@ -111,7 +111,7 @@ static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_
 
         r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_L2MISS, v->l2miss);
         if (r < 0) {
-                log_error_netdev(netdev,
+                log_netdev_error(netdev,
                                  "Could not append IFLA_VXLAN_L2MISS attribute: %s",
                                  strerror(-r));
                 return r;
@@ -119,7 +119,7 @@ static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_
 
         r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_L3MISS, v->l3miss);
         if (r < 0) {
-                log_error_netdev(netdev,
+                log_netdev_error(netdev,
                                  "Could not append IFLA_VXLAN_L3MISS attribute: %s",
                                  strerror(-r));
                 return r;
@@ -128,7 +128,7 @@ static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_
         if(v->fdb_ageing) {
                 r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_AGEING, v->fdb_ageing / USEC_PER_SEC);
                 if (r < 0) {
-                        log_error_netdev(netdev,
+                        log_netdev_error(netdev,
                                          "Could not append IFLA_VXLAN_AGEING attribute: %s",
                                          strerror(-r));
                         return r;

commit b6a3ca6d876ab59b4f29ed67f54ef87005177906
Author: Tom Gundersen <teg at jklm.no>
Date:   Thu Dec 4 12:19:27 2014 +0100

    networkctl: use the shared functions for enumerating the local gateways

diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index 6c5eb5b..815ea16 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -375,118 +375,34 @@ static int get_gateway_description(sd_rtnl *rtnl, struct udev_hwdb *hwdb, int if
 }
 
 static int dump_gateways(sd_rtnl *rtnl, struct udev_hwdb *hwdb, const char *prefix, int ifindex) {
-        _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL;
-        sd_rtnl_message *m;
-        bool first = true;
-        int r;
-
-        assert(rtnl);
-        assert(ifindex >= 0);
-
-        r = sd_rtnl_message_new_route(rtnl, &req, RTM_GETROUTE, AF_UNSPEC, RTPROT_UNSPEC);
-        if (r < 0)
-                return r;
-
-        r = sd_rtnl_message_request_dump(req, true);
-        if (r < 0)
-                return r;
-
-        r = sd_rtnl_call(rtnl, req, 0, &reply);
-        if (r < 0)
-                return r;
-
-        for (m = reply; m; m = sd_rtnl_message_next(m)) {
-                _cleanup_free_ char *gateway = NULL, *gateway_description = NULL;
-                union in_addr_union gw = {};
-                uint16_t type;
-                uint32_t ifi;
-                int family;
-
-                r = sd_rtnl_message_get_errno(m);
-                if (r < 0) {
-                        log_error_errno(r, "got error: %m");
-                        continue;
-                }
-
-                r = sd_rtnl_message_get_type(m, &type);
-                if (r < 0) {
-                        log_error_errno(r, "could not get type: %m");
-                        continue;
-                }
-
-                if (type != RTM_NEWROUTE) {
-                        log_error("type is not RTM_NEWROUTE");
-                        continue;
-                }
-
-                r = sd_rtnl_message_route_get_family(m, &family);
-                if (r < 0) {
-                        log_error_errno(r, "could not get family: %m");
-                        continue;
-                }
-
-                r = sd_rtnl_message_read_u32(m, RTA_OIF, &ifi);
-                if (r < 0) {
-                        log_error_errno(r, "could not get RTA_OIF: %m");
-                        continue;
-                }
-
-                if (ifindex > 0 && ifi != (unsigned) ifindex)
-                        continue;
-
-                switch (family) {
-                case AF_INET:
-                        r = sd_rtnl_message_read_in_addr(m, RTA_GATEWAY, &gw.in);
-                        if (r < 0)
-                                continue;
-
-                        r = sd_rtnl_message_read_in_addr(m, RTA_DST, NULL);
-                        if (r >= 0)
-                                continue;
-
-                        r = sd_rtnl_message_read_in_addr(m, RTA_SRC, NULL);
-                        if (r >= 0)
-                                continue;
-
-                        break;
-                case AF_INET6:
-                        r = sd_rtnl_message_read_in6_addr(m, RTA_GATEWAY, &gw.in6);
-                        if (r < 0)
-                                continue;
-
-                        r = sd_rtnl_message_read_in6_addr(m, RTA_DST, NULL);
-                        if (r >= 0)
-                                continue;
+        _cleanup_free_ struct local_address *local = NULL;
+        int r, n, i;
 
-                        r = sd_rtnl_message_read_in6_addr(m, RTA_SRC, NULL);
-                        if (r >= 0)
-                                continue;
+        n = local_gateways(rtnl, ifindex, AF_UNSPEC, &local);
+        if (n < 0)
+                return n;
 
-                        break;
-                default:
-                        continue;
-                }
+        for (i = 0; i < n; i++) {
+                _cleanup_free_ char *gateway = NULL, *description = NULL;
 
-                r = in_addr_to_string(family, &gw, &gateway);
+                r = in_addr_to_string(local[i].family, &local[i].address, &gateway);
                 if (r < 0)
-                        continue;
+                        return r;
 
-                r = get_gateway_description(rtnl, hwdb, ifi, family, &gw, &gateway_description);
+                r = get_gateway_description(rtnl, hwdb, ifindex, local[i].family, &local[i].address, &description);
                 if (r < 0)
-                        log_debug("could not get description of gateway: %s", strerror(-r));
+                        log_debug_errno(r, "Could not get description of gateway: %m");
 
-                if (gateway_description)
+                if (description)
                         printf("%*s%s (%s)\n",
                                (int) strlen(prefix),
-                               first ? prefix : "",
-                               gateway, gateway_description);
+                               i == 0 ? prefix : "",
+                               gateway, description);
                 else
                         printf("%*s%s\n",
                                (int) strlen(prefix),
-                               first ? prefix : "",
+                               i == 0 ? prefix : "",
                                gateway);
-
-                first = false;
         }
 
         return 0;



More information about the systemd-commits mailing list