is a list of changes: - Ignore interfaces that are not listed in the configuration file: fixes an abort when trying to configure interface located in a different rdomain and doesn't look to the address of interfaces outside the configuration (otherwise it would pick the wrong interface in some cases). - Improve the routing code: use a rb-tree to store groups avoiding group duplications and having to fix hand-rolled list implementations. - Fixed some warnings and improved debug messages. As discussed with ajacoutot@, ok reyk@
94 lines
2.6 KiB
Plaintext
94 lines
2.6 KiB
Plaintext
$OpenBSD: patch-config_c,v 1.3 2016/12/23 13:44:31 rzalamena Exp $
|
|
--- config.c.orig Thu Dec 15 19:50:23 2016
|
|
+++ config.c Mon Dec 19 21:02:00 2016
|
|
@@ -177,7 +177,7 @@
|
|
}
|
|
|
|
// Loop through all VIFs...
|
|
- for ( Ix = 0; Dp = getIfByIx( Ix ); Ix++ ) {
|
|
+ for ( Ix = 0; (Dp = getIfByIx( Ix )); Ix++ ) {
|
|
if ( Dp->InAdr.s_addr && ! (Dp->Flags & IFF_LOOPBACK) ) {
|
|
|
|
// Now try to find a matching config...
|
|
@@ -241,11 +241,10 @@
|
|
tmpPtr->allowednets = NULL;
|
|
|
|
// Make a copy of the token to store the IF name
|
|
- tmpPtr->name = (char *)malloc( sizeof(char) * strlen(token) );
|
|
+ tmpPtr->name = strdup(token);
|
|
if(tmpPtr->name == NULL) {
|
|
log(LOG_ERR, 0, "Out of memory.");
|
|
}
|
|
- strcpy(tmpPtr->name, token);
|
|
|
|
// Set the altnet pointer to the allowednets pointer.
|
|
anetPtr = &tmpPtr->allowednets;
|
|
@@ -255,8 +254,6 @@
|
|
while(token != NULL) {
|
|
if(strcmp("altnet", token)==0) {
|
|
// Altnet...
|
|
- struct in_addr networkAddr;
|
|
-
|
|
token = nextConfigToken();
|
|
IF_DEBUG log(LOG_DEBUG, 0, "Config: IF: Got altnet token %s.",token);
|
|
|
|
@@ -328,29 +325,18 @@
|
|
*/
|
|
struct SubnetList *parseSubnetAddress(char *addrstr) {
|
|
struct SubnetList *tmpSubnet;
|
|
- char *tmpStr;
|
|
uint32 addr = 0x00000000;
|
|
uint32 mask = 0xFFFFFFFF;
|
|
+ int bitcnt;
|
|
|
|
- // First get the network part of the address...
|
|
- tmpStr = strtok(addrstr, "/");
|
|
- addr = inet_addr(tmpStr);
|
|
-
|
|
- tmpStr = strtok(NULL, "/");
|
|
- if(tmpStr != NULL) {
|
|
- int bitcnt = atoi(tmpStr);
|
|
- if(bitcnt <= 0 || bitcnt > 32) {
|
|
- log(LOG_WARNING, 0, "The bits part of the address is invalid : %d.",tmpStr);
|
|
- return NULL;
|
|
- }
|
|
-
|
|
- mask <<= (32 - bitcnt);
|
|
- }
|
|
-
|
|
- if(addr == -1 || addr == 0) {
|
|
- log(LOG_WARNING, 0, "Unable to parse address token '%s'.", addrstr);
|
|
+ bitcnt = inet_net_pton(AF_INET, addrstr, &addr, sizeof(addr));
|
|
+ if(bitcnt<0) {
|
|
+ log(LOG_WARNING, 0, "Unable to parse address token '%s'.",addrstr);
|
|
return NULL;
|
|
- }
|
|
+ } else if(bitcnt>0)
|
|
+ mask <<= (32 - bitcnt);
|
|
+ else
|
|
+ mask = 0;
|
|
|
|
tmpSubnet = (struct SubnetList*) malloc(sizeof(struct SubnetList));
|
|
tmpSubnet->subnet_addr = addr;
|
|
@@ -363,3 +349,20 @@
|
|
return tmpSubnet;
|
|
}
|
|
|
|
+struct vifconfig *
|
|
+config_getinterface(const char *ifname)
|
|
+{
|
|
+ struct vifconfig *vc;
|
|
+
|
|
+ if (vifconf == NULL)
|
|
+ return (NULL);
|
|
+
|
|
+ for (vc = vifconf; vc; vc = vc->next) {
|
|
+ if (strcmp(vc->name, ifname))
|
|
+ continue;
|
|
+
|
|
+ return (vc);
|
|
+ }
|
|
+
|
|
+ return (NULL);
|
|
+}
|