chiark / gitweb /
netlink: Move local_address into struct netlink
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 3 May 2014 11:10:11 +0000 (12:10 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 3 May 2014 15:36:13 +0000 (16:36 +0100)
All the actual netlinks have this, and proper ICMP generation on
point-to-point links is going to need it.

The dummy "null" netlink previously didn't have this parameter; now,
it is mandatory.  This is an incompatible configuration change, but
only for configurations which contain a null netlink - which we think
is only done for testing or debugging.

No other functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
netlink.c
netlink.h
slip.c
tun.c

index b14d2eb..954dbb6 100644 (file)
--- a/netlink.c
+++ b/netlink.c
@@ -1198,6 +1198,8 @@ netlink_deliver_fn *netlink_init(struct netlink *st,
        st->remote_networks=ipset_complement(empty);
        ipset_free(empty);
     }
+    st->local_address=string_item_to_ipaddr(
+       dict_find_item(dict,"local-address", True, "netlink", loc),"netlink");
 
     sa=dict_find_item(dict,"secnet-address",False,"netlink",loc);
     ptpa=dict_find_item(dict,"ptp-address",False,"netlink",loc);
index 7c42716..b24c6ef 100644 (file)
--- a/netlink.h
+++ b/netlink.h
@@ -48,6 +48,7 @@ struct netlink {
     struct ipset *networks; /* Local networks */
     struct subnet_list *subnets; /* Same as networks, for display */
     struct ipset *remote_networks; /* Allowable remote networks */
+    uint32_t local_address; /* host interface address */
     uint32_t secnet_address; /* our own address, or the address of the
                                other end of a point-to-point link */
     bool_t ptp;
diff --git a/slip.c b/slip.c
index aed2551..17b3c18 100644 (file)
--- a/slip.c
+++ b/slip.c
@@ -27,7 +27,6 @@ struct slip {
     bool_t ignoring_packet; /* If this packet was corrupt or overlong,
                               we ignore everything up to the next END */
     netlink_deliver_fn *netlink_to_tunnel;
-    uint32_t local_address;
 };
 
 /* Generic SLIP mangling code */
@@ -147,8 +146,6 @@ static void slip_init(struct slip *st, struct cloc loc, dict_t *dict,
        netlink_init(&st->nl,st,loc,dict,
                     "netlink-userv-ipif",NULL,to_host);
     st->buff=find_cl_if(dict,"buffer",CL_BUFFER,True,"name",loc);
-    st->local_address=string_item_to_ipaddr(
-       dict_find_item(dict,"local-address", True, name, loc),"netlink");
     BUF_ALLOC(st->buff,"slip_init");
     st->pending_esc=False;
     st->ignoring_packet=False;
@@ -297,7 +294,7 @@ static void userv_invoke_userv(struct userv *st)
 
     addrs=safe_malloc(512,"userv_invoke_userv:addrs");
     snprintf(addrs,512,"%s,%s,%d,slip",
-            ipaddr_to_string(st->slip.local_address),
+            ipaddr_to_string(st->slip.nl.local_address),
             ipaddr_to_string(st->slip.nl.secnet_address),st->slip.nl.mtu);
 
     allnets=ipset_new();
diff --git a/tun.c b/tun.c
index 40bf6dd..dcfd623 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -81,7 +81,6 @@ struct tun {
     struct buffer_if *buff; /* We receive packets into here
                               and send them to the netlink code. */
     netlink_deliver_fn *netlink_to_tunnel;
-    uint32_t local_address; /* host interface address */
 };
 
 static cstring_t tun_flavour_str(uint32_t flavour)
@@ -353,7 +352,7 @@ static void tun_phase_hook(void *sst, uint32_t newphase)
        to set the TUN device's address, and route to add routes to all
        our networks. */
 
-    hostaddr=ipaddr_to_string(st->local_address);
+    hostaddr=ipaddr_to_string(st->nl.local_address);
     secnetaddr=ipaddr_to_string(st->nl.secnet_address);
     snprintf(mtu,sizeof(mtu),"%d",st->nl.mtu);
     mtu[5]=0;
@@ -387,7 +386,7 @@ static void tun_phase_hook(void *sst, uint32_t newphase)
        sa=(struct sockaddr_in *)&ifr.ifr_addr;
        FILLZERO(*sa);
        sa->sin_family=AF_INET;
-       sa->sin_addr.s_addr=htonl(st->local_address);
+       sa->sin_addr.s_addr=htonl(st->nl.local_address);
        if (ioctl(fd,SIOCSIFADDR, &ifr)!=0) {
            fatal_perror("tun_apply: SIOCSIFADDR");
        }
@@ -491,8 +490,6 @@ static list_t *tun_create(closure_t *self, struct cloc loc, dict_t *context,
     st->route_path=dict_read_string(dict,"route-path",False,"tun-netlink",loc);
 
     st->buff=find_cl_if(dict,"buffer",CL_BUFFER,True,"tun-netlink",loc);
-    st->local_address=string_item_to_ipaddr(
-       dict_find_item(dict,"local-address", True, "netlink", loc),"netlink");
 
     if (st->tun_flavour==TUN_FLAVOUR_GUESS) {
        /* If we haven't been told what type of TUN we're using, take