patch-2.1.27 linux/net/ax25/ax25_route.c

Next file: linux/net/ax25/ax25_std_in.c
Previous file: linux/net/ax25/ax25_out.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.26/linux/net/ax25/ax25_route.c linux/net/ax25/ax25_route.c
@@ -1,5 +1,5 @@
 /*
- *	AX.25 release 035
+ *	AX.25 release 036
  *
  *	This is ALPHA test software. This code may break your machine, randomly fail to work with new 
  *	releases, misbehave and/or generally screw up. It might even work. 
@@ -67,22 +67,9 @@
 #include <linux/mm.h>
 #include <linux/interrupt.h>
 
-static struct ax25_route {
-	struct ax25_route *next;
-	ax25_address callsign;
-	struct device *dev;
-	ax25_digi *digipeat;
-	char ip_mode;
-} *ax25_route = NULL;
-
-struct ax25_dev ax25_device[AX25_MAX_DEVICES] = {
-	{"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL},
-	{"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL},
-	{"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL},
-	{"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}
-};
+static ax25_route *ax25_route_list = NULL;
 
-static struct ax25_route *ax25_find_route(ax25_address *, struct device *);
+static ax25_route *ax25_find_route(ax25_address *, struct device *);
 
 /*
  * small macro to drop non-digipeated digipeaters and reverse path
@@ -102,25 +89,25 @@
 
 void ax25_rt_device_down(struct device *dev)
 {
-	struct ax25_route *s, *t, *ax25_rt = ax25_route;
+	ax25_route *s, *t, *ax25_rt = ax25_route_list;
 	
 	while (ax25_rt != NULL) {
 		s       = ax25_rt;
 		ax25_rt = ax25_rt->next;
 
 		if (s->dev == dev) {
-			if (ax25_route == s) {
-				ax25_route = s->next;
+			if (ax25_route_list == s) {
+				ax25_route_list = s->next;
 				if (s->digipeat != NULL)
-					kfree_s((void *)s->digipeat, sizeof(ax25_digi));
-				kfree_s((void *)s, (sizeof *s));
+					kfree_s(s->digipeat, sizeof(ax25_digi));
+				kfree_s(s, sizeof(ax25_route));
 			} else {
-				for (t = ax25_route; t != NULL; t = t->next) {
+				for (t = ax25_route_list; t != NULL; t = t->next) {
 					if (t->next == s) {
 						t->next = s->next;
 						if (s->digipeat != NULL)
-							kfree_s((void *)s->digipeat, sizeof(ax25_digi));
-						kfree_s((void *)s, sizeof(*s));
+							kfree_s(s->digipeat, sizeof(ax25_digi));
+						kfree_s(s, sizeof(ax25_route));
 						break;
 					}
 				}
@@ -132,10 +119,10 @@
 int ax25_rt_ioctl(unsigned int cmd, void *arg)
 {
 	unsigned long flags;
-	struct ax25_route *s, *t, *ax25_rt;
+	ax25_route *s, *t, *ax25_rt;
 	struct ax25_routes_struct route;
 	struct ax25_route_opt_struct rt_option;
-	struct device *dev;
+	ax25_dev *ax25_dev;
 	int i, err;
 
 	switch (cmd) {
@@ -143,12 +130,12 @@
 			if ((err = verify_area(VERIFY_READ, arg, sizeof(route))) != 0)
 				return err;		
 			copy_from_user(&route, arg, sizeof(route));
-			if ((dev = ax25rtr_get_dev(&route.port_addr)) == NULL)
+			if ((ax25_dev = ax25_addr_ax25dev(&route.port_addr)) == NULL)
 				return -EINVAL;
 			if (route.digi_count > AX25_MAX_DIGIS)
 				return -EINVAL;
-			for (ax25_rt = ax25_route; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
-				if (ax25cmp(&ax25_rt->callsign, &route.dest_addr) == 0 && ax25_rt->dev == dev) {
+			for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
+				if (ax25cmp(&ax25_rt->callsign, &route.dest_addr) == 0 && ax25_rt->dev == ax25_dev->dev) {
 					if (ax25_rt->digipeat != NULL) {
 						kfree_s(ax25_rt->digipeat, sizeof(ax25_digi));
 						ax25_rt->digipeat = NULL;
@@ -166,15 +153,15 @@
 					return 0;
 				}
 			}
-			if ((ax25_rt = (struct ax25_route *)kmalloc(sizeof(struct ax25_route), GFP_ATOMIC)) == NULL)
+			if ((ax25_rt = kmalloc(sizeof(ax25_route), GFP_ATOMIC)) == NULL)
 				return -ENOMEM;
 			ax25_rt->callsign     = route.dest_addr;
-			ax25_rt->dev          = dev;
+			ax25_rt->dev          = ax25_dev->dev;
 			ax25_rt->digipeat     = NULL;
 			ax25_rt->ip_mode      = ' ';
 			if (route.digi_count != 0) {
 				if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
-					kfree_s(ax25_rt, sizeof(struct ax25_route));
+					kfree_s(ax25_rt, sizeof(ax25_route));
 					return -ENOMEM;
 				}
 				ax25_rt->digipeat->lastrepeat = -1;
@@ -184,10 +171,9 @@
 					ax25_rt->digipeat->calls[i]    = route.digi_addr[i];
 				}
 			}
-			save_flags(flags);
-			cli();
-			ax25_rt->next = ax25_route;
-			ax25_route    = ax25_rt;
+			save_flags(flags); cli();
+			ax25_rt->next   = ax25_route_list;
+			ax25_route_list = ax25_rt;
 			restore_flags(flags);
 			break;
 
@@ -195,25 +181,25 @@
 			if ((err = verify_area(VERIFY_READ, arg, sizeof(route))) != 0)
 				return err;
 			copy_from_user(&route, arg, sizeof(route));
-			if ((dev = ax25rtr_get_dev(&route.port_addr)) == NULL)
+			if ((ax25_dev = ax25_addr_ax25dev(&route.port_addr)) == NULL)
 				return -EINVAL;
-			ax25_rt = ax25_route;
+			ax25_rt = ax25_route_list;
 			while (ax25_rt != NULL) {
 				s       = ax25_rt;
 				ax25_rt = ax25_rt->next;
-				if (s->dev == dev && ax25cmp(&route.dest_addr, &s->callsign) == 0) {
-					if (ax25_route == s) {
-						ax25_route = s->next;
+				if (s->dev == ax25_dev->dev && ax25cmp(&route.dest_addr, &s->callsign) == 0) {
+					if (ax25_route_list == s) {
+						ax25_route_list = s->next;
 						if (s->digipeat != NULL)
-							kfree_s((void *)s->digipeat, sizeof(ax25_digi));
-						kfree_s((void *)s, (sizeof *s));
+							kfree_s(s->digipeat, sizeof(ax25_digi));
+						kfree_s(s, sizeof(ax25_route));
 					} else {
-						for (t = ax25_route; t != NULL; t = t->next) {
+						for (t = ax25_route_list; t != NULL; t = t->next) {
 							if (t->next == s) {
 								t->next = s->next;
 								if (s->digipeat != NULL)
-									kfree_s((void *)s->digipeat, sizeof(ax25_digi));
-								kfree_s((void *)s, sizeof(*s));
+									kfree_s(s->digipeat, sizeof(ax25_digi));
+								kfree_s(s, sizeof(ax25_route));
 								break;
 							}
 						}				
@@ -226,10 +212,10 @@
 			if ((err = verify_area(VERIFY_READ, arg, sizeof(rt_option))) != 0)
 				return err;
 			copy_from_user(&rt_option, arg, sizeof(rt_option));
-			if ((dev = ax25rtr_get_dev(&rt_option.port_addr)) == NULL)
+			if ((ax25_dev = ax25_addr_ax25dev(&rt_option.port_addr)) == NULL)
 				return -EINVAL;
-			for (ax25_rt = ax25_route; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
-				if (ax25_rt->dev == dev && ax25cmp(&rt_option.dest_addr, &ax25_rt->callsign) == 0) {
+			for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
+				if (ax25_rt->dev == ax25_dev->dev && ax25cmp(&rt_option.dest_addr, &ax25_rt->callsign) == 0) {
 					switch (rt_option.cmd) {
 						case AX25_SET_RT_IPMODE:
 							switch (rt_option.arg) {
@@ -258,7 +244,7 @@
 
 int ax25_rt_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
 {
-	struct ax25_route *ax25_rt;
+	ax25_route *ax25_rt;
 	int len     = 0;
 	off_t pos   = 0;
 	off_t begin = 0;
@@ -269,7 +255,7 @@
 
 	len += sprintf(buffer, "callsign  dev  mode digipeaters\n");
 
-	for (ax25_rt = ax25_route; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
+	for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
 		if (ax25cmp(&ax25_rt->callsign, &null_ax25_address) == 0)
 			callsign = "default";
 		else
@@ -317,55 +303,20 @@
 	return len;
 } 
 
-int ax25_cs_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
-{
-	ax25_uid_assoc *pt;
-	int len     = 0;
-	off_t pos   = 0;
-	off_t begin = 0;
-
-	cli();
-
-	len += sprintf(buffer, "Policy: %d\n", ax25_uid_policy);
-
-	for (pt = ax25_uid_list; pt != NULL; pt = pt->next) {
-		len += sprintf(buffer + len, "%6d %s\n", pt->uid, ax2asc(&pt->call));
-
-		pos = begin + len;
-
-		if (pos < offset) {
-			len = 0;
-			begin = pos;
-		}
-
-		if (pos > offset + length)
-			break;
-	}
-
-	sti();
-
-	*start = buffer + (offset - begin);
-	len   -= offset - begin;
-
-	if (len > length) len = length;
-
-	return len;
-}
-
 /*
  *	Find AX.25 route
  */
-static struct ax25_route *ax25_find_route(ax25_address *addr, struct device *dev)
+static ax25_route *ax25_find_route(ax25_address *addr, struct device *dev)
 {
-	struct ax25_route *ax25_spe_rt = NULL;
-	struct ax25_route *ax25_def_rt = NULL;
-	struct ax25_route *ax25_rt;
+	ax25_route *ax25_spe_rt = NULL;
+	ax25_route *ax25_def_rt = NULL;
+	ax25_route *ax25_rt;
 
 	/*
 	 *	Bind to the physical interface we heard them on, or the default
 	 *	route if none is found;
 	 */
-	for (ax25_rt = ax25_route; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
+	for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
 		if (dev == NULL) {
 			if (ax25cmp(&ax25_rt->callsign, addr) == 0 && ax25_rt->dev != NULL)
 				ax25_spe_rt = ax25_rt;
@@ -408,18 +359,19 @@
  */
 int ax25_rt_autobind(ax25_cb *ax25, ax25_address *addr)
 {
-	struct ax25_route *ax25_rt;
+	ax25_route *ax25_rt;
 	ax25_address *call;
 
 	if ((ax25_rt = ax25_find_route(addr, NULL)) == NULL)
 		return -EHOSTUNREACH;
 
-	ax25->device = ax25_rt->dev;
+	if ((ax25->ax25_dev = ax25_dev_ax25dev(ax25_rt->dev)) == NULL)
+		return -EHOSTUNREACH;
 
 	if ((call = ax25_findbyuid(current->euid)) == NULL) {
 		if (ax25_uid_policy && !suser())
 			return -EPERM;
-		call = (ax25_address *)ax25->device->dev_addr;
+		call = (ax25_address *)ax25->ax25_dev->dev->dev_addr;
 	}
 
 	ax25->source_addr = *call;
@@ -443,7 +395,7 @@
  */
 void ax25_rt_build_path(ax25_cb *ax25, ax25_address *addr, struct device *dev)
 {
-	struct ax25_route *ax25_rt;
+	ax25_route *ax25_rt;
 
 	if ((ax25_rt = ax25_find_route(addr, dev)) == NULL)
 		return;
@@ -454,14 +406,16 @@
 	if ((ax25->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL)
 		return;
 
-	ax25->device    = ax25_rt->dev;
+	if ((ax25->ax25_dev = ax25_dev_ax25dev(ax25_rt->dev)) == NULL)
+		return;
+
 	*ax25->digipeat = *ax25_rt->digipeat;
 	ax25_adjust_path(addr, ax25->digipeat);
 }
 
 void ax25_dg_build_path(struct sk_buff *skb, ax25_address *addr, struct device *dev)
 {
-	struct ax25_route *ax25_rt;
+	ax25_route *ax25_rt;
 	ax25_digi digipeat;
 	ax25_address src, dest;
 	unsigned char *bp;
@@ -491,7 +445,7 @@
 
 	bp = skb_push(skb, len);
 
-	build_ax25_addr(bp, &src, &dest, ax25_rt->digipeat, AX25_COMMAND, AX25_MODULUS);
+	ax25_addr_build(bp, &src, &dest, ax25_rt->digipeat, AX25_COMMAND, AX25_MODULUS);
 }
 
 /*
@@ -499,154 +453,23 @@
  */
 char ax25_ip_mode_get(ax25_address *callsign, struct device *dev)
 {
-	struct ax25_route *ax25_rt;
+	ax25_route *ax25_rt;
 
-	for (ax25_rt = ax25_route; ax25_rt != NULL; ax25_rt = ax25_rt->next)
+	for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next)
 		if (ax25cmp(&ax25_rt->callsign, callsign) == 0 && ax25_rt->dev == dev)
 			return ax25_rt->ip_mode;
 
 	return ' ';
 }
 
-static struct ax25_dev *ax25_dev_get_dev(struct device *dev)
-{
-	int i;
-
-	for (i = 0; i < AX25_MAX_DEVICES; i++)
-		if (ax25_device[i].dev != NULL && ax25_device[i].dev == dev)
-			return ax25_device + i;
-
-	return NULL;
-}
-
-/*
- *	Wow, a bit of data hiding. Is this C++ or what ?
- */
-int ax25_dev_get_value(struct device *dev, int valueno)
-{
-	struct ax25_dev *ax25_dev;
-
-	if ((ax25_dev = ax25_dev_get_dev(dev)) == NULL) {
-		printk(KERN_WARNING "ax25_dev_get_value called with invalid device\n");
-		return 1;
-	}
-
-	return ax25_dev->values[valueno];
-}
-
-/*
- *	This is called when an interface is brought up. These are
- *	reasonable defaults.
- */
-void ax25_dev_device_up(struct device *dev)
-{
-	struct ax25_dev *ax25_dev = NULL;
-	int i;
-
-	for (i = 0; i < AX25_MAX_DEVICES; i++) {
-		if (ax25_device[i].dev == NULL) {
-			ax25_dev = ax25_device + i;
-			break;
-		}
-	}
-
-	if (ax25_dev == NULL) {
-		printk(KERN_ERR "ax25_dev_device_up cannot find free AX.25 device\n");
-		return;
-	}
-
-	ax25_unregister_sysctl();
-
-	sprintf(ax25_dev->name, "%s.parms", dev->name);
-
-	ax25_dev->dev     = dev;
-	ax25_dev->forward = NULL;
-
-	ax25_dev->values[AX25_VALUES_IPDEFMODE] = AX25_DEF_IPDEFMODE;
-	ax25_dev->values[AX25_VALUES_AXDEFMODE] = AX25_DEF_AXDEFMODE;
-	ax25_dev->values[AX25_VALUES_TEXT]      = AX25_DEF_TEXT;
-	ax25_dev->values[AX25_VALUES_BACKOFF]   = AX25_DEF_BACKOFF;
-	ax25_dev->values[AX25_VALUES_CONMODE]   = AX25_DEF_CONMODE;
-	ax25_dev->values[AX25_VALUES_WINDOW]    = AX25_DEF_WINDOW;
-	ax25_dev->values[AX25_VALUES_EWINDOW]   = AX25_DEF_EWINDOW;
-	ax25_dev->values[AX25_VALUES_T1]        = AX25_DEF_T1;
-	ax25_dev->values[AX25_VALUES_T2]        = AX25_DEF_T2;
-	ax25_dev->values[AX25_VALUES_T3]        = AX25_DEF_T3;
-	ax25_dev->values[AX25_VALUES_IDLE]	= AX25_DEF_IDLE;
-	ax25_dev->values[AX25_VALUES_N2]        = AX25_DEF_N2;
-	ax25_dev->values[AX25_VALUES_DIGI]      = AX25_DEF_DIGI;
-	ax25_dev->values[AX25_VALUES_PACLEN]	= AX25_DEF_PACLEN;
-	ax25_dev->values[AX25_VALUES_MAXQUEUE]	= AX25_DEF_MAXQUEUE;
-
-	ax25_register_sysctl();
-}
-
-void ax25_dev_device_down(struct device *dev)
-{
-	struct ax25_dev *ax25_dev;
-
-	ax25_unregister_sysctl();
-
-	if ((ax25_dev = ax25_dev_get_dev(dev)) != NULL)
-		ax25_dev->dev = NULL;
-
-	ax25_register_sysctl();
-}
-
-int ax25_fwd_ioctl(unsigned int cmd, struct ax25_fwd_struct *fwd)
-{
-	struct device *dev;
-	struct ax25_dev *ax25_dev;
-
-	if ((dev = ax25rtr_get_dev(&fwd->port_from)) == NULL)
-		return -EINVAL;
-
-	if ((ax25_dev = ax25_dev_get_dev(dev)) == NULL)
-		return -EINVAL;
-
-	switch (cmd) {
-		case SIOCAX25ADDFWD:
-			if ((dev = ax25rtr_get_dev(&fwd->port_to)) == NULL)
-				return -EINVAL;
-			if (ax25_dev->forward != NULL)
-				return -EINVAL;
-			ax25_dev->forward = dev;
-			break;
-
-		case SIOCAX25DELFWD:
-			if (ax25_dev->forward == NULL)
-				return -EINVAL;
-			ax25_dev->forward = NULL;
-			break;
-
-		default:
-			return -EINVAL;
-	}
-
-	return 0;
-}
-
-struct device *ax25_fwd_dev(struct device *dev)
-{
-	struct ax25_dev *ax25_dev;
-
-	if ((ax25_dev = ax25_dev_get_dev(dev)) == NULL)
-		return dev;
-
-	if (ax25_dev->forward == NULL)
-		return dev;
-
-	return ax25_dev->forward;
-}
-
 #ifdef MODULE
 
 /*
- *	Free all memory associated with routing and device structures.
+ *	Free all memory associated with routing structures.
  */
 void ax25_rt_free(void)
 {
-	struct ax25_route *s, *ax25_rt = ax25_route;
+	ax25_route *s, *ax25_rt = ax25_route_list;
 
 	while (ax25_rt != NULL) {
 		s       = ax25_rt;
@@ -655,7 +478,7 @@
 		if (s->digipeat != NULL)
 			kfree_s(s->digipeat, sizeof(ax25_digi));
 
-		kfree_s(s, sizeof(struct ax25_route));
+		kfree_s(s, sizeof(ax25_route));
 	}
 }
 

FUNET's LINUX-ADM group, [email protected]
TCL-scripts by Sam Shen, [email protected]