[systemd-devel] [PATCH] networkd: add preferred source to dhcp4 gateway route

Tom Gundersen teg at jklm.no
Mon Sep 8 06:06:41 PDT 2014


Applied. Thanks!

Tom

On Fri, Sep 5, 2014 at 11:56 AM, Emil Renner Berthing <systemd at esmil.dk> wrote:
> This makes DHCPv4 and IPv4LL coexist peacefully.
> ---
>  src/network/networkd-dhcp4.c | 11 +++++++++++
>  src/network/networkd-route.c | 22 ++++++++++++++++++++++
>  src/network/networkd.h       |  2 ++
>  3 files changed, 35 insertions(+)
>
> diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
> index 5e4ff2b..748db09 100644
> --- a/src/network/networkd-dhcp4.c
> +++ b/src/network/networkd-dhcp4.c
> @@ -67,9 +67,18 @@ static int link_set_dhcp_routes(Link *link) {
>                  return r;
>          }
>          if (r >= 0) {
> +                struct in_addr address;
>                  _cleanup_route_free_ Route *route = NULL;
>                  _cleanup_route_free_ Route *route_gw = NULL;
>
> +                r = sd_dhcp_lease_get_address(link->dhcp_lease, &address);
> +                if (r < 0) {
> +                        log_warning_link(link,
> +                                         "DHCP error: could not get address: %s",
> +                                         strerror(-r));
> +                        return r;
> +                }
> +
>                  r = route_new_dynamic(&route, RTPROT_DHCP);
>                  if (r < 0) {
>                          log_error_link(link,
> @@ -92,6 +101,8 @@ static int link_set_dhcp_routes(Link *link) {
>                  route_gw->family = AF_INET;
>                  route_gw->dst_addr.in = gateway;
>                  route_gw->dst_prefixlen = 32;
> +                route_gw->prefsrc_addr.in = address;
> +                route_gw->prefsrc_set = 1;
>                  route_gw->scope = RT_SCOPE_LINK;
>                  route_gw->metrics = DHCP_ROUTE_METRIC;
>
> diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
> index aead4fb..c4be3f4 100644
> --- a/src/network/networkd-route.c
> +++ b/src/network/networkd-route.c
> @@ -144,6 +144,17 @@ int route_drop(Route *route, Link *link,
>                  }
>          }
>
> +        if (route->prefsrc_set) {
> +                if (route->family == AF_INET)
> +                        r = sd_rtnl_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in);
> +                else if (route->family == AF_INET6)
> +                        r = sd_rtnl_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in6);
> +                if (r < 0) {
> +                        log_error("Could not append RTA_PREFSRC attribute: %s", strerror(-r));
> +                        return r;
> +                }
> +        }
> +
>          r = sd_rtnl_message_route_set_scope(req, route->scope);
>          if (r < 0) {
>                  log_error("Could not set scope: %s", strerror(-r));
> @@ -218,6 +229,17 @@ int route_configure(Route *route, Link *link,
>                  }
>          }
>
> +        if (route->prefsrc_set) {
> +                if (route->family == AF_INET)
> +                        r = sd_rtnl_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in);
> +                else if (route->family == AF_INET6)
> +                        r = sd_rtnl_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in6);
> +                if (r < 0) {
> +                        log_error("Could not append RTA_PREFSRC attribute: %s", strerror(-r));
> +                        return r;
> +                }
> +        }
> +
>          r = sd_rtnl_message_route_set_scope(req, route->scope);
>          if (r < 0) {
>                  log_error("Could not set scope: %s", strerror(-r));
> diff --git a/src/network/networkd.h b/src/network/networkd.h
> index ab5df1a..b32eb31 100644
> --- a/src/network/networkd.h
> +++ b/src/network/networkd.h
> @@ -144,12 +144,14 @@ struct Route {
>
>          int family;
>          unsigned char dst_prefixlen;
> +        unsigned char prefsrc_set;
>          unsigned char scope;
>          uint32_t metrics;
>          unsigned char protocol;  /* RTPROT_* */
>
>          union in_addr_union in_addr;
>          union in_addr_union dst_addr;
> +        union in_addr_union prefsrc_addr;
>
>          LIST_FIELDS(Route, routes);
>  };
> --
> 2.1.0
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list