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>
return this_host_ipaddr;
}
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;
+}
{"radius_timeout", OT_INT, ST_UNDEF, NULL},
{"radius_retries", OT_INT, ST_UNDEF, NULL},
{"nas_identifier", OT_STR, ST_UNDEF, ""},
{"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},
};
/* local options */
{"login_local", OT_STR, ST_UNDEF, NULL},
};
sin = (struct sockaddr_in *) & salocal;
memset ((char *) sin, '\0', (size_t) length);
sin->sin_family = AF_INET;
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)
sin->sin_port = htons ((unsigned short) 0);
if (bind (sockfd, (struct sockaddr *) sin, length) < 0 ||
getsockname (sockfd, (struct sockaddr *) sin, &length) < 0)