patch for iproute
Hi everybody,
I am part of the LEAF project - a small distro for embedded environments - at http://leaf.sourceforge.net (I'm actually only part of the "Bering uClibc" branch, to be precise).
Since LEAF does not provide ifconfig and route by default (just iproute2) I created a patch that allows using OpenVPN on LEAF boxes without the need for ifconfig and route.
I would be very happy to see this integrated into OpenVPN at some point (there's no hurry - we have a mostly automated build environment, so applying the patch is no big deal).
I've tested the patch using a LEAF box plus a regular Fedora box (both tun and tap devices) and everything seems to be working nicely.
If the patch doesn't make it onto the list (the LEAF lists trim all attachments), it can also be found at:
http://cvs.sourceforge.net/viewcvs.py/leaf/src/bering-uclibc/apps/openvpn/iproute.patch
Let me know if you have any questions.
Martin
misc.c +26 -0
@@ -680,3 +680,29 @@ ++cp; } } + + +/* +* 'stolen' from busybox networking/ifupdown.c +*/ +unsigned int count_bits (unsigned int a) +{ +unsigned int result; + result = (a &0x55 ) + ((a >>1 ) &0x55 ); + result = (result &0x33 ) + ((result >>2 ) &0x33 ); +return ((result &0x0F ) + ((result >>4 ) &0x0F )); +} + +int count_netmask_bits (const char *dotted_quad) +{ +unsigned int result, a, b, c, d; +/* Found a netmask... Check if it is dotted quad */ +if (sscanf (dotted_quad,"%u.%u.%u.%u" , &a, &b, &c, &d) !=4 ) +return -1 ; + result =count_bits (a); + result +=count_bits (b); + result +=count_bits (c); + result +=count_bits (d); +return ((int )result); +} +
misc.h +5 -0
@@ -138,6 +139,10 @@void setenv_int (const char *name,int value);void setenv_del (const char *name); +/* convert netmasks for iproute2 */ +int count_netmask_bits (const char *); +unsigned int count_bits (unsigned int ); +/* make cp safe to be passed to system() or set as an environmental variable */ void safe_string (char *cp);
@@ -171,3 +176,4 @@ }#endif +
route.c +16 -2
@@ -525,6 +525,7 @@setenv_route (&rl->routes[i], i +1 ); } +static void add_route (struct route *r) {
@@ -545,14 +546,22 @@ gateway =print_in_addr_t (r->gateway, false);#if defined(TARGET_LINUX ) +#ifdef CONFIG_FEATURE_IPROUTE +buf_printf (&buf,IPROUTE_PATH " route add %s/%d via %s" , + network, +count_netmask_bits (netmask), + gateway); +if (r->metric_defined) +buf_printf (&buf," metric %d" , r->metric); +#else buf_printf (&buf,ROUTE_PATH " add -net %s netmask %s gw %s" , network, netmask, gateway);if (r->metric_defined)buf_printf (&buf," metric %d" , r->metric); - +#endif /*CONFIG_FEATURE_IPROUTE*/ msg (D_ROUTE ,"%s" ,BSTR (&buf)); status =system_check (BSTR (&buf),"ERROR: Linux route add command failed" , false);
@@ -650,11 +659,16 @@ gateway =print_in_addr_t (r->gateway, false);#if defined(TARGET_LINUX ) +#ifdef CONFIG_FEATURE_IPROUTE +buf_printf (&buf,IPROUTE_PATH " route del %s/%d" , + network, +count_netmask_bits (netmask)); +#else buf_printf (&buf,ROUTE_PATH " del -net %s netmask %s" , network, netmask); - +#endif /*CONFIG_FEATURE_IPROUTE*/ msg (D_ROUTE ,"%s" ,BSTR (&buf));system_check (BSTR (&buf),"ERROR: Linux route delete command failed" , false);
tun.c +40 -1
54 lines not on this page · raw message
configure.ac +15 -0
@@ -106,6 +106,14 @@ ) AC_DEFINE_UNQUOTED(IFCONFIG_PATH, "$IFCONFIG", [Path to ifconfig tool]) +AC_ARG_WITH(iproute-path, + [ --with-iproute-path=PATH Path to iproute tool], + [IPROUTE="$withval"], + [AC_PATH_PROG([IPROUTE], [ip], [ip], [$PATH:/usr/local/sbin:/usr/sbin:/sbin])] +) +AC_DEFINE_UNQUOTED(IPROUTE_PATH, "$IPROUTE", [Path to iproute tool]) + + AC_ARG_WITH(route-path, [ --with-route-path=PATH Path to route tool], [ROUTE="$withval"],
@@ -118,6 +126,13 @@ [LEAK="$withval"] ) +AC_ARG_ENABLE(iproute2, + [ --enable-iproute2 Enable support for iproute2], + AC_DEFINE(CONFIG_FEATURE_IPROUTE, 1, [enable iproute2 support]) + +) + + dnl Guess host type. AC_CANONICAL_HOST AC_CANONICAL_SYSTEM
Martin,
Thanks for the patch -- it looks good and I expect to merge it. I see that you hardwire the choice for iproute2 vs. vanilla ip route + ifconfig at build time. Do you think that makes sense, or would it be better to have an --iproute2 run time flag?
James
Quoted 14 lines · Martin Hejl
Hi everybody,
I am part of the LEAF project - a small distro for embedded environments
- at http://leaf.sourceforge.net (I'm actually only part of the "Bering uClibc" branch, to be precise).Since LEAF does not provide ifconfig and route by default (just iproute2) I created a patch that allows using OpenVPN on LEAF boxes without the need for ifconfig and route.
I would be very happy to see this integrated into OpenVPN at some point (there's no hurry - we have a mostly automated build environment, so applying the patch is no big deal).
Quoted 6 lines
I've tested the patch using a LEAF box plus a regular Fedora box (both tun and tap devices) and everything seems to be working nicely.
If the patch doesn't make it onto the list (the LEAF lists trim all attachments), it can also be found at:
http://cvs.sourceforge.net/viewcvs.py/leaf/src/bering-uclibc/apps/openvpn/iproute.patch
Quoted 5 lines
Let me know if you have any questions.
Martin
Hi James,
Quoted 1 line
Thanks for the patch -- it looks good and I expect to merge it.
Thanks - sounds good to me.
Quoted 4 lines
I see that
you hardwire the choice for iproute2 vs. vanilla ip route + ifconfig at build time. Do you think that makes sense, or would it be better to have an --iproute2 run time flag?
Two reasons, basically. First of all, I'm lazy, so I wanted the patch to be as short as possible (and a runtime option probably would have meant having to make more changes than a define). It was simply very straight forward to add the code and then add the options to configure.ac Besides, a run-time option would have meant having to "disturb" much more code - and I wanted to keep the change as isolated as possible. Easier to test if things still work, and less chances that I've screwed up something else.
And second, my guess is that at the moment, a plattform with only iproute2 is still pretty exotic (so the option would not be needed for most people) - and the plattforms that only have iproute2 (like LEAF) are focusing on minimizing the size of all packages - so I didn't want to increase the size of the binary if I could.
I know, both reasons aren't terribly good - if you feel that it would make life for you or package maintainers easier if it's a runtime option, feel free to change it (I know that compile time options are a pain for packagers). I guess for somebody familiar with the code, it should be rather simple (but I won't pretend I'm familiar with the OpenVPN sources - it was easy enough to find the places I needed to change that I didn't dig around in the other modules too much).
Martin