along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: subnet.c,v 1.1.2.6 2000/10/28 16:41:40 guus Exp $
+ $Id: subnet.c,v 1.1.2.9 2000/11/03 22:35:12 zarq Exp $
*/
#include "config.h"
-#include <utils.h>
-#include <xalloc.h>
-#include "subnet.h"
+#include <stdio.h>
+#include <syslog.h>
+
+#include "conf.h"
#include "net.h"
+#include "subnet.h"
+#include "system.h"
+
+#include <utils.h>
+#include <xalloc.h>
/* lists type of subnet */
/* Link it into the owners list of subnets (unsorted) */
- subnet->next = cl->subnets->next;
+ subnet->next = cl->subnets;
subnet->prev = NULL;
if(subnet->next)
subnet->next->prev = subnet;
insert before first -> add it in front of list
rest: insert after another subnet
*/
-
+cp
if(subnet_list[subnet->type])
{
p = q = subnet_list[subnet->type];
q = p;
}
}
-
- if(!subnet_list[subnet->type] || p == subnet_list[subnet->type]) /* First two cases */
+cp
+ if(p == subnet_list[subnet->type]) /* First two cases */
{
/* Insert in front */
subnet->global_next = subnet_list[subnet->type];
subnet->global_prev = q;
q->global_next = subnet;
}
-
+cp
if(subnet->global_next)
subnet->global_next->global_prev = subnet;
cp
/* Remove it from owner's list */
if(subnet->prev)
- {
- subnet->prev->next = subnet->next;
- }
+ subnet->prev->next = subnet->next;
else
- {
- subnet->owner->subnets = subnet->next;
- }
+ subnet->owner->subnets = subnet->next;
- subnet->next->prev = subnet->prev;
+ if(subnet->next)
+ subnet->next->prev = subnet->prev;
/* Remove it from the global list */
if(subnet->global_prev)
- {
- subnet->global_prev->global_next = subnet->global_next;
- }
+ subnet->global_prev->global_next = subnet->global_next;
else
- {
- subnet_list[subnet->type] = subnet->global_next;
- }
+ subnet_list[subnet->type] = subnet->global_next;
- subnet->global_next->global_prev = subnet->global_prev;
+ if(subnet->global_next)
+ subnet->global_next->global_prev = subnet->global_prev;
free_subnet(subnet);
cp
cp
if(sscanf(subnetstr, "%d,", &type) != 1)
return NULL;
-
+cp
subnet = new_subnet();
-
+cp
switch(type)
{
case SUBNET_MAC:
return NULL;
}
break;
- break;
default:
free_subnet(subnet);
return NULL;
subnet->net.mac.address.x[3],
subnet->net.mac.address.x[4],
subnet->net.mac.address.x[5]);
+ break;
case SUBNET_IPV4:
asprintf(&netstr, "%d,%lx/%lx", subnet->type, subnet->net.ipv4.address, subnet->net.ipv4.mask);
+ break;
case SUBNET_IPV6:
asprintf(&netstr, "%d,%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx/%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
subnet->net.ipv6.address.x[0],
subnet->net.ipv6.mask.x[5],
subnet->net.ipv6.mask.x[6],
subnet->net.ipv6.mask.x[7]);
+ break;
default:
- netstr = NULL;
+ asprintf(&netstr, _("unknown"));
}
cp
return netstr;
{
subnet_t *subnet;
cp
- for(subnet = subnet_list[SUBNET_MAC]; subnet != NULL; subnet = subnet->next)
+ for(subnet = subnet_list[SUBNET_MAC]; subnet != NULL; subnet = subnet->global_next)
{
if(memcmp(&address, &subnet->net.mac.address, sizeof(address)) == 0)
break;
{
subnet_t *subnet;
cp
- for(subnet = subnet_list[SUBNET_IPV4]; subnet != NULL; subnet = subnet->next)
+ for(subnet = subnet_list[SUBNET_IPV4]; subnet != NULL; subnet = subnet->global_next)
{
if((address & subnet->net.ipv4.mask) == subnet->net.ipv4.address)
break;
subnet_t *subnet;
int i;
cp
- for(subnet = subnet_list[SUBNET_IPV6]; subnet != NULL; subnet = subnet->next)
+ for(subnet = subnet_list[SUBNET_IPV6]; subnet != NULL; subnet = subnet->global_next)
{
for(i=0; i<8; i++)
if((address.x[i] & subnet->net.ipv6.mask.x[i]) != subnet->net.ipv6.address.x[i])
break;
- if(i=8)
+ if(i == 8)
break;
}
cp
return subnet;
}
+
+void dump_subnet_list(void)
+{
+ subnet_t *subnet;
+ char *netstr;
+cp
+ syslog(LOG_DEBUG, _("Subnet list:"));
+
+ for(subnet = subnet_list[SUBNET_IPV4]; subnet != NULL; subnet = subnet->global_next)
+ {
+ netstr = net2str(subnet);
+ syslog(LOG_DEBUG, " %s owner %s", netstr, subnet->owner->name);
+ free(netstr);
+ }
+
+ syslog(LOG_DEBUG, _("End of subnet list."));
+cp
+}