dhclient should be more specific on routes

2015-02-09 Thread Claudio Jeker
This diff makes sure that the route dhclient installes is actually over
the interface dhclient runs on and not an other one with the same network.
This also removes the conflict detection we have at the moment.

OK?
-- 
:wq Claudio

Index: dhclient.c
===
RCS file: /cvs/src/sbin/dhclient/dhclient.c,v
retrieving revision 1.357
diff -u -p -r1.357 dhclient.c
--- dhclient.c  7 Feb 2015 10:08:06 -   1.357
+++ dhclient.c  8 Feb 2015 01:20:45 -
@@ -108,7 +108,7 @@ void apply_ignore_list(char *);
 
 void add_direct_route(struct in_addr, struct in_addr, struct in_addr);
 void add_default_route(struct in_addr, struct in_addr);
-void add_static_routes(struct option_data *);
+void add_static_routes(struct option_data *, struct in_addr);
 void add_classless_static_routes(struct option_data *, struct in_addr);
 
 int compare_lease(struct client_lease *, struct client_lease *);
@@ -964,7 +964,7 @@ bind_lease(void)
add_default_route(client-active-address, gateway);
}
if (options[DHO_STATIC_ROUTES].len)
-   add_static_routes(options[DHO_STATIC_ROUTES]);
+   add_static_routes(options[DHO_STATIC_ROUTES], 
client-active-address);
}
 
 newlease:
@@ -1060,13 +1060,6 @@ dhcpoffer(struct in_addr client_addr, st
}
 
/*
-* Reject offers whose subnet is already configured on another
-* interface.
-*/
-   if (subnet_exists(lease))
-   return;
-
-   /*
 * If this lease was acquired through a BOOTREPLY, record that
 * fact.
 */
@@ -2443,7 +2436,9 @@ priv_write_file(char *path, int flags, m
 void
 add_direct_route(struct in_addr dest, struct in_addr mask, struct in_addr 
iface)
 {
-   add_route(dest, mask, iface,
+   struct in_addr ifa = { 0 };
+
+   add_route(dest, mask, iface, ifa,
RTA_DST | RTA_NETMASK | RTA_GATEWAY, RTF_CLONING | RTF_STATIC);
 }
 
@@ -2473,15 +2468,15 @@ add_default_route(struct in_addr addr, s
 * claiming there is no gateway address to use.
 */
if (bcmp(gateway, addr, sizeof(addr)) != 0) {
-   addrs |= RTA_GATEWAY;
+   addrs |= RTA_GATEWAY | RTA_IFA;
flags |= RTF_GATEWAY | RTF_STATIC;
}
 
-   add_route(dest, netmask, gateway, addrs, flags);
+   add_route(dest, netmask, gateway, addr, addrs, flags);
 }
 
 void
-add_static_routes(struct option_data *static_routes)
+add_static_routes(struct option_data *static_routes, struct in_addr iface)
 {
struct in_addr   dest, netmask, gateway;
struct in_addr   *addr;
@@ -2499,8 +2494,8 @@ add_static_routes(struct option_data *st
gateway.s_addr = (addr+1)-s_addr;
 
/* XXX Order implies priority but we're ignoring that. */
-   add_route(dest, netmask, gateway,
-   RTA_DST | RTA_GATEWAY, RTF_GATEWAY | RTF_STATIC);
+   add_route(dest, netmask, gateway, iface,
+   RTA_DST | RTA_GATEWAY | RTA_IFA, RTF_GATEWAY | RTF_STATIC);
}
 }
 
@@ -2537,8 +2532,8 @@ add_classless_static_routes(struct optio
if (gateway.s_addr == INADDR_ANY)
add_direct_route(dest, netmask, iface);
else
-   add_route(dest, netmask, gateway,
-   RTA_DST | RTA_GATEWAY | RTA_NETMASK,
+   add_route(dest, netmask, gateway, iface,
+   RTA_DST | RTA_GATEWAY | RTA_NETMASK | RTA_IFA,
RTF_GATEWAY | RTF_STATIC);
}
 }
Index: dhcpd.h
===
RCS file: /cvs/src/sbin/dhclient/dhcpd.h,v
retrieving revision 1.148
diff -u -p -r1.148 dhcpd.h
--- dhcpd.h 7 Feb 2015 02:07:32 -   1.148
+++ dhcpd.h 7 Feb 2015 04:28:40 -
@@ -261,7 +261,6 @@ void interface_link_forceup(char *);
 int interface_status(char *);
 int get_rdomain(char *);
 void get_hw_address(void);
-int subnet_exists(struct client_lease *);
 
 /* tables.c */
 extern const struct option dhcp_options[256];
@@ -301,7 +300,7 @@ void add_address(struct in_addr, struct 
 
 void flush_routes(void);
 
-void add_route(struct in_addr, struct in_addr, struct in_addr, int, int);
+void add_route(struct in_addr, struct in_addr, struct in_addr, struct in_addr, 
int, int);
 
 void sendhup(struct client_lease *);
 
Index: kroute.c
===
RCS file: /cvs/src/sbin/dhclient/kroute.c,v
retrieving revision 1.74
diff -u -p -r1.74 kroute.c
--- kroute.c8 Feb 2015 01:20:40 -   1.74
+++ kroute.c8 Feb 2015 06:53:37 -
@@ -162,8 +162,8 @@ priv_flush_routes(struct imsg_flush_rout
 }
 
 void
-add_route(struct in_addr dest, struct in_addr netmask, struct in_addr gateway,
-

Re: dhclient should be more specific on routes

2015-02-09 Thread Martin Pieuchot
On 10/02/15(Tue) 03:07, Claudio Jeker wrote:
 This diff makes sure that the route dhclient installes is actually over
 the interface dhclient runs on and not an other one with the same network.
 This also removes the conflict detection we have at the moment.

In general it's a good practice to give as much information as we know
when creating a route.

It works for me on my trunk setup.

Could you wrap the two lines below to 80 char?  With that ok mpi@.

 Index: dhclient.c
 ===
 RCS file: /cvs/src/sbin/dhclient/dhclient.c,v
 retrieving revision 1.357
 diff -u -p -r1.357 dhclient.c
 --- dhclient.c7 Feb 2015 10:08:06 -   1.357
 +++ dhclient.c8 Feb 2015 01:20:45 -
 @@ -108,7 +108,7 @@ void   apply_ignore_list(char *);
  
  void add_direct_route(struct in_addr, struct in_addr, struct in_addr);
  void add_default_route(struct in_addr, struct in_addr);
 -void add_static_routes(struct option_data *);
 +void add_static_routes(struct option_data *, struct in_addr);
  void add_classless_static_routes(struct option_data *, struct in_addr);
  
  int compare_lease(struct client_lease *, struct client_lease *);
 @@ -964,7 +964,7 @@ bind_lease(void)
   add_default_route(client-active-address, gateway);
   }
   if (options[DHO_STATIC_ROUTES].len)
 - add_static_routes(options[DHO_STATIC_ROUTES]);
 + add_static_routes(options[DHO_STATIC_ROUTES], 
 client-active-address);
^^

here

 Index: dhcpd.h
 ===
 RCS file: /cvs/src/sbin/dhclient/dhcpd.h,v
 retrieving revision 1.148
 diff -u -p -r1.148 dhcpd.h
 --- dhcpd.h   7 Feb 2015 02:07:32 -   1.148
 +++ dhcpd.h   7 Feb 2015 04:28:40 -
 @@ -261,7 +261,6 @@ void interface_link_forceup(char *);
  int interface_status(char *);
  int get_rdomain(char *);
  void get_hw_address(void);
 -int subnet_exists(struct client_lease *);
  
  /* tables.c */
  extern const struct option dhcp_options[256];
 @@ -301,7 +300,7 @@ void add_address(struct in_addr, struct 
  
  void flush_routes(void);
  
 -void add_route(struct in_addr, struct in_addr, struct in_addr, int, int);
 +void add_route(struct in_addr, struct in_addr, struct in_addr, struct 
 in_addr, int, int);
^

and here :)