From: Roy Marples Date: Fri, 26 Feb 2010 20:37:30 +0000 (+0000) Subject: Enable net.ipv4.conf.$iface.promote_secondaries on Linux so that X-Git-Tag: v5.2.0~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=255e14dab144a3f6cb1910d9ea164afa9ff98220;p=thirdparty%2Fdhcpcd.git Enable net.ipv4.conf.$iface.promote_secondaries on Linux so that we keep the subnet when changing addresses on the same subnet. --- diff --git a/if-bsd.c b/if-bsd.c index 58c405f8..05a2d515 100644 --- a/if-bsd.c +++ b/if-bsd.c @@ -72,6 +72,13 @@ static int r_fd = -1; +int +if_init(_unused struct interface *iface) +{ + /* BSD promotes secondary address by default */ + return 0; +} + int init_sockets(void) { diff --git a/if-linux.c b/if-linux.c index d24b956e..705f7753 100644 --- a/if-linux.c +++ b/if-linux.c @@ -59,6 +59,32 @@ static int sock_fd; static struct sockaddr_nl sock_nl; +int +if_init(struct interface *iface) +{ + char path[PATH_MAX]; + FILE *fp; + int n; + + /* We enable promote_secondaries so that we can do this + * add 192.168.1.2/24 + * add 192.168.1.3/24 + * del 192.168.1.2/24 + * and the subnet mask moves onto 192.168.1.3/24 + * This matches the behaviour of BSD which makes coding dhcpcd + * a little easier as there's just one behaviour. */ + snprintf(path, sizeof(path), + "/proc/sys/net/ipv4/conf/%s/promote_secondaries", + iface->name); + + fp = fopen(path, "w"); + if (fp == NULL) + return errno == ENOENT ? 0 : -1; + n = fprintf(fp, "1"); + fclose(fp); + return n == -1 ? -1 : 0; +} + static int _open_link_socket(struct sockaddr_nl *nl) { diff --git a/net.c b/net.c index b55a7108..20edd0e7 100644 --- a/net.c +++ b/net.c @@ -449,6 +449,14 @@ discover_interfaces(int argc, char * const *argv) "%s: unknown hardware family", p); } } + + /* Handle any platform init for the interface */ + if (if_init(ifp) == -1) { + syslog(LOG_ERR, "%s: if_init: %m", p); + free_interface(ifp); + continue; + } + if (ifl) ifl->next = ifp; else diff --git a/net.h b/net.h index d1e9c066..4f92f0a7 100644 --- a/net.h +++ b/net.h @@ -105,6 +105,8 @@ int inet_ntocidr(struct in_addr); int inet_cidrtoaddr(int, struct in_addr *); int up_interface(struct interface *); +int if_init(struct interface *); + int do_address(const char *, struct in_addr *, struct in_addr *, struct in_addr *, int); int if_address(const struct interface *, diff --git a/platform-linux.c b/platform-linux.c index c0bc5994..99cb4a35 100644 --- a/platform-linux.c +++ b/platform-linux.c @@ -25,9 +25,6 @@ * SUCH DAMAGE. */ -#include -#include - #include #include #include