[systemd-devel] [PATCH 1/3] networkd: tunnel improve logging
Tom Gundersen
teg at jklm.no
Wed Apr 29 12:54:36 PDT 2015
Applied. Thanks!
Tom
On Wed, Apr 22, 2015 at 10:44 AM, Susant Sahani <susant at redhat.com> wrote:
> Replaces a lof ot strerror() usage with log_netdev_error_errno()
> ---
> src/network/networkd-netdev-tunnel.c | 240 ++++++++++-------------------------
> 1 file changed, 64 insertions(+), 176 deletions(-)
>
> diff --git a/src/network/networkd-netdev-tunnel.c b/src/network/networkd-netdev-tunnel.c
> index 89ad3ee..7aa9317 100644
> --- a/src/network/networkd-netdev-tunnel.c
> +++ b/src/network/networkd-netdev-tunnel.c
> @@ -54,44 +54,24 @@ static int netdev_ipip_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_m
> assert(t->family == AF_INET);
>
> r = sd_rtnl_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_LINK attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
>
> r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_LOCAL attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m");
>
> r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_REMOTE attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m");
>
> r = sd_rtnl_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_TTL attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_TTL attribute: %m");
>
> r = sd_rtnl_message_append_u8(m, IFLA_IPTUN_PMTUDISC, t->pmtudisc);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_PMTUDISC attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_PMTUDISC attribute: %m");
>
> return r;
> }
> @@ -107,44 +87,24 @@ static int netdev_sit_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_me
> assert(t->family == AF_INET);
>
> r = sd_rtnl_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_LINK attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
>
> r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_LOCAL attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m");
>
> r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_REMOTE attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m");
>
> r = sd_rtnl_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_TTL attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_TTL attribute: %m");
>
> r = sd_rtnl_message_append_u8(m, IFLA_IPTUN_PMTUDISC, t->pmtudisc);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_PMTUDISC attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_PMTUDISC attribute: %m");
>
> return r;
> }
> @@ -156,9 +116,9 @@ static int netdev_gre_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_me
> assert(netdev);
>
> if (netdev->kind == NETDEV_KIND_GRE)
> - t = GRE(netdev);
> + t = GRE(netdev);
> else
> - t = GRETAP(netdev);
> + t = GRETAP(netdev);
>
> assert(t);
> assert(t->family == AF_INET);
> @@ -166,52 +126,28 @@ static int netdev_gre_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_me
> assert(m);
>
> r = sd_rtnl_message_append_u32(m, IFLA_GRE_LINK, link->ifindex);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_GRE_LINK attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m");
>
> r = sd_rtnl_message_append_in_addr(m, IFLA_GRE_LOCAL, &t->local.in);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_GRE_LOCAL attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LOCAL attribute: %m");
>
> r = sd_rtnl_message_append_in_addr(m, IFLA_GRE_REMOTE, &t->remote.in);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_GRE_REMOTE attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_REMOTE attribute: %m");
>
> r = sd_rtnl_message_append_u8(m, IFLA_GRE_TTL, t->ttl);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_GRE_TTL attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_TTL attribute: %m");
>
> r = sd_rtnl_message_append_u8(m, IFLA_GRE_TOS, t->tos);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_GRE_TOS attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_TOS attribute: %m");
>
> r = sd_rtnl_message_append_u8(m, IFLA_GRE_PMTUDISC, t->pmtudisc);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_GRE_PMTUDISC attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_PMTUDISC attribute: %m");
>
> return r;
> }
> @@ -223,9 +159,9 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_rtnl
> assert(netdev);
>
> if (netdev->kind == NETDEV_KIND_IP6GRE)
> - t = IP6GRE(netdev);
> + t = IP6GRE(netdev);
> else
> - t = IP6GRETAP(netdev);
> + t = IP6GRETAP(netdev);
>
> assert(t);
> assert(t->family == AF_INET6);
> @@ -233,36 +169,20 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_rtnl
> assert(m);
>
> r = sd_rtnl_message_append_u32(m, IFLA_GRE_LINK, link->ifindex);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_GRE_LINK attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m");
>
> r = sd_rtnl_message_append_in6_addr(m, IFLA_GRE_LOCAL, &t->local.in6);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_GRE_LOCAL attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LOCAL attribute: %m");
>
> r = sd_rtnl_message_append_in6_addr(m, IFLA_GRE_REMOTE, &t->remote.in6);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_GRE_REMOTE attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_REMOTE attribute: %m");
>
> r = sd_rtnl_message_append_u8(m, IFLA_GRE_TTL, t->ttl);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_GRE_TTL attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_TTL attribute: %m");
>
> return r;
> }
> @@ -278,28 +198,16 @@ static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_me
> assert(t->family == AF_INET);
>
> r = sd_rtnl_message_append_u32(m, IFLA_VTI_LINK, link->ifindex);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_LINK attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
>
> r = sd_rtnl_message_append_in_addr(m, IFLA_VTI_LOCAL, &t->local.in);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_LOCAL attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m");
>
> r = sd_rtnl_message_append_in_addr(m, IFLA_VTI_REMOTE, &t->remote.in);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_REMOTE attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m");
>
> return r;
> }
> @@ -316,36 +224,20 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_rtnl
> assert(t->family == AF_INET6);
>
> r = sd_rtnl_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_LINK attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
>
> r = sd_rtnl_message_append_in6_addr(m, IFLA_IPTUN_LOCAL, &t->local.in6);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_LOCAL attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m");
>
> r = sd_rtnl_message_append_in6_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in6);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_REMOTE attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m");
>
> r = sd_rtnl_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_TTL attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_TTL attribute: %m");
>
> switch (t->ip6tnl_mode) {
> case NETDEV_IP6_TNL_MODE_IP6IP6:
> @@ -361,12 +253,8 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_rtnl
> }
>
> r = sd_rtnl_message_append_u8(m, IFLA_IPTUN_PROTO, proto);
> - if (r < 0) {
> - log_netdev_error(netdev,
> - "Could not append IFLA_IPTUN_MODE attribute: %s",
> - strerror(-r));
> - return r;
> - }
> + if (r < 0)
> + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_MODE attribute: %m");
>
> return r;
> }
> @@ -409,13 +297,13 @@ static int netdev_tunnel_verify(NetDev *netdev, const char *filename) {
> assert(t);
>
> if (t->remote.in.s_addr == INADDR_ANY) {
> - log_warning("Tunnel without remote address configured in %s. Ignoring", filename);
> - return -EINVAL;
> + log_warning("Tunnel without remote address configured in %s. Ignoring", filename);
> + return -EINVAL;
> }
>
> if (t->family != AF_INET && t->family != AF_INET6) {
> - log_warning("Tunnel with invalid address family configured in %s. Ignoring", filename);
> - return -EINVAL;
> + log_warning("Tunnel with invalid address family configured in %s. Ignoring", filename);
> + return -EINVAL;
> }
>
> if (netdev->kind == NETDEV_KIND_IP6TNL) {
> --
> 2.3.5
>
More information about the systemd-devel
mailing list