]> git.ozlabs.org Git - ppp.git/commitdiff
plugins/radius: Handle bindaddr keyword in radiusclient.conf
authorAdrian Ban <adrian.ban@mantech.ro>
Wed, 3 Apr 2013 20:19:52 +0000 (23:19 +0300)
committerPaul Mackerras <paulus@samba.org>
Sat, 11 May 2013 11:43:37 +0000 (21:43 +1000)
This adds code to the radius plugin to handle the bindaddr keyword in
/etc/radiusclient/radiusclient.conf, thus allowing the administrator
to specify which local IP address to use when sending packets to the
radius server.

This is very common for setups where the router has multiple
interfaces for upstream and you don't know which connection is active.
In this case sometimes the packet uses the IP of interface 1 and
sometimes uses the IP of interface 2.  With this patch (adapted from
radiusclient-ng) you can specify the IP of the loopback address, and
the plugin will bind to that IP and send the packet with a fixed IP
every time.

Slimmed a little bit at James Carlson's suggestion.

Signed-off-by: Paul Mackerras <paulus@samba.org>
pppd/plugins/radius/ip_util.c
pppd/plugins/radius/options.h
pppd/plugins/radius/sendserver.c

index cd59e7b5213cbe2ef9c71c9511741c335cf69999..1f6a76e480f935a8410188d079e8424bb45b5ea3 100644 (file)
@@ -135,3 +135,31 @@ UINT4 rc_own_ipaddress(void)
 
        return this_host_ipaddr;
 }
+
+/*
+ * Function: rc_own_bind_ipaddress
+ *
+ * Purpose: get the IP address to be used as a source address
+ *          for sending requests in host order
+ *
+ * Returns: IP address
+ *
+ */
+
+UINT4 rc_own_bind_ipaddress(void)
+{
+       char *bindaddr;
+       UINT4 rval = 0;
+
+       if ((bindaddr = rc_conf_str("bindaddr")) == NULL ||
+           strcmp(rc_conf_str("bindaddr"), "*") == 0) {
+               rval = INADDR_ANY;
+       } else {
+               if ((rval = rc_get_ipaddr(bindaddr)) == 0) {
+                       error("rc_own_bind_ipaddress: couldn't get IP address from bindaddr");
+                       rval = INADDR_ANY;
+               }
+       }
+
+       return rval;
+}
index aa55305ac275b45598aca201393c544d2511d979..f4ad986a032efa472ebd2a6c49c2e66a1a816457 100644 (file)
@@ -55,6 +55,7 @@ static OPTION config_options[] = {
 {"radius_timeout",     OT_INT, ST_UNDEF, NULL},
 {"radius_retries",     OT_INT, ST_UNDEF, NULL},
 {"nas_identifier",      OT_STR, ST_UNDEF, ""},
+{"bindaddr",            OT_STR, ST_UNDEF, NULL},
 /* local options */
 {"login_local",                OT_STR, ST_UNDEF, NULL},
 };
index 3612b8d57a88a8f291bd8b84635c5838f7390b09..f68aa67f0380617b5941c1c574b9201b2731b30d 100644 (file)
@@ -244,7 +244,7 @@ int rc_send_server (SEND_DATA *data, char *msg, REQUEST_INFO *info)
        sin = (struct sockaddr_in *) & salocal;
        memset ((char *) sin, '\0', (size_t) length);
        sin->sin_family = AF_INET;
-       sin->sin_addr.s_addr = htonl(INADDR_ANY);
+       sin->sin_addr.s_addr = htonl(rc_own_bind_ipaddress());
        sin->sin_port = htons ((unsigned short) 0);
        if (bind (sockfd, (struct sockaddr *) sin, length) < 0 ||
                   getsockname (sockfd, (struct sockaddr *) sin, &length) < 0)