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

Next file: linux/net/ax25/ax25_subr.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.8/linux/net/ax25/ax25_route.c linux/net/ax25/ax25_route.c
@@ -1,5 +1,5 @@
 /*
- *	AX.25 release 032
+ *	AX.25 release 033
  *
  *	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. 
@@ -37,11 +37,12 @@
  *			Joerg(DL1BKE)	Fixed AX.25 routing of IP datagram and VC, new ioctl()
  *					"SIOCAX25OPTRT" to set IP mode and a 'permanent' flag
  *					on routes.
- *	AX.25 032	Jonathan(G4KLX)	Remove auto-router.
+ *	AX.25 033	Jonathan(G4KLX)	Remove auto-router.
+ *			Joerg(DL1BKE)	Moved BPQ Ethernet driver to seperate device.
  */
  
 #include <linux/config.h>
-#ifdef CONFIG_AX25
+#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/socket.h>
@@ -72,11 +73,12 @@
 	char ip_mode;
 } *ax25_route = NULL;
 
-static struct ax25_dev {
-	struct ax25_dev *next;
-	struct device *dev;
-	unsigned short values[AX25_MAX_VALUES];
-} *ax25_device = 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 struct ax25_route *ax25_find_route(ax25_address *, struct device *);
 
@@ -504,30 +506,20 @@
 	return ' ';
 }
 
-static struct ax25_dev *ax25_dev_get_dev(struct device *dev)
-{
-	struct ax25_dev *s;
-
-	for (s = ax25_device; s != NULL; s = s->next)
-		if (s->dev == dev)
-			return s;
-	
-	return NULL;
-}
-
 /*
  *	Wow, a bit of data hiding. Is this C++ or what ?
  */
-unsigned short ax25_dev_get_value(struct device *dev, int valueno)
+int ax25_dev_get_value(struct device *dev, int valueno)
 {
-	struct ax25_dev *ax25_dev;
+	int i;
 
-	if ((ax25_dev = ax25_dev_get_dev(dev)) == NULL) {
-		printk(KERN_WARNING "ax25_dev_get_flag called with invalid device\n");
-		return 1;
-	}
+	for (i = 0; i < AX25_MAX_DEVICES; i++)
+		if (ax25_device[i].dev != NULL && ax25_device[i].dev == dev)
+			return ax25_device[i].values[valueno];
+	
+	printk(KERN_WARNING "ax25_dev_get_value called with invalid device\n");
 
-	return ax25_dev->values[valueno];
+	return 0;
 }
 
 /*
@@ -536,17 +528,29 @@
  */
 void ax25_dev_device_up(struct device *dev)
 {
-	unsigned long flags;
-	struct ax25_dev *ax25_dev;
+	struct ax25_dev *ax25_dev = NULL;
+	int i;
 	
-	if ((ax25_dev = (struct ax25_dev *)kmalloc(sizeof(struct ax25_dev), GFP_ATOMIC)) == NULL)
-		return;		/* No space */
+	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->dev = dev;
 
 	ax25_dev->values[AX25_VALUES_IPDEFMODE] = AX25_DEF_IPDEFMODE;
 	ax25_dev->values[AX25_VALUES_AXDEFMODE] = AX25_DEF_AXDEFMODE;
-	ax25_dev->values[AX25_VALUES_NETROM]    = AX25_DEF_NETROM;
 	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;
@@ -559,227 +563,45 @@
 	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_IPMAXQUEUE]= AX25_DEF_IPMAXQUEUE;
+	ax25_dev->values[AX25_VALUES_MAXQUEUE]	= AX25_DEF_MAXQUEUE;
 
-	save_flags(flags);
-	cli();
-
-	ax25_dev->next = ax25_device;
-	ax25_device    = ax25_dev;
-
-	restore_flags(flags);
+	ax25_register_sysctl();
 }
 
 void ax25_dev_device_down(struct device *dev)
 {
-	struct ax25_dev *s, *t, *ax25_dev = ax25_device;
-	
-	while (ax25_dev != NULL) {
-		s        = ax25_dev;
-		ax25_dev = ax25_dev->next;
-
-		if (s->dev == dev) {
-			if (ax25_device == s) {
-				ax25_device = s->next;
-				kfree_s((void *)s, (sizeof *s));
-			} else {
-				for (t = ax25_device; t != NULL; t = t->next) {
-					if (t->next == s) {
-						t->next = s->next;
-						kfree_s((void *)s, sizeof(*s));
-						break;
-					}
-				}				
-			}
-		}
-	}
-}
-
-int ax25_dev_ioctl(unsigned int cmd, void *arg)
-{
-	struct ax25_parms_struct ax25_parms;
-	struct device *dev;
-	struct ax25_dev *ax25_dev;
-	int err;
+	int i;
 
-	switch (cmd) {
-		case SIOCAX25SETPARMS:
-			if (!suser())
-				return -EPERM;
-			if ((err = verify_area(VERIFY_READ, arg, sizeof(ax25_parms))) != 0)
-				return err;
-			copy_from_user(&ax25_parms, arg, sizeof(ax25_parms));
-			if ((dev = ax25rtr_get_dev(&ax25_parms.port_addr)) == NULL)
-				return -EINVAL;
-			if ((ax25_dev = ax25_dev_get_dev(dev)) == NULL)
-				return -EINVAL;
-			if (ax25_parms.values[AX25_VALUES_IPDEFMODE] != 'D' &&
-			    ax25_parms.values[AX25_VALUES_IPDEFMODE] != 'V')
-				return -EINVAL;
-			if (ax25_parms.values[AX25_VALUES_AXDEFMODE] != MODULUS &&
-			    ax25_parms.values[AX25_VALUES_AXDEFMODE] != EMODULUS)
-				return -EINVAL;
-			if (ax25_parms.values[AX25_VALUES_NETROM] != 0 &&
-			    ax25_parms.values[AX25_VALUES_NETROM] != 1)
-				return -EINVAL;
-			if (ax25_parms.values[AX25_VALUES_TEXT] != 0 &&
-			    ax25_parms.values[AX25_VALUES_TEXT] != 1)
-				return -EINVAL;
-			if (ax25_parms.values[AX25_VALUES_BACKOFF] != 'E' &&
-			    ax25_parms.values[AX25_VALUES_BACKOFF] != 'L')
-				return -EINVAL;
-			if (ax25_parms.values[AX25_VALUES_CONMODE] != 0 &&
-			    ax25_parms.values[AX25_VALUES_CONMODE] != 1)
-				return -EINVAL;
-			if (ax25_parms.values[AX25_VALUES_WINDOW] < 1 ||
-			    ax25_parms.values[AX25_VALUES_WINDOW] > 7)
-				return -EINVAL;
-			if (ax25_parms.values[AX25_VALUES_EWINDOW] < 1 ||
-			    ax25_parms.values[AX25_VALUES_EWINDOW] > 63)
-				return -EINVAL;
-			if (ax25_parms.values[AX25_VALUES_T1] < 1)
-				return -EINVAL;
-			if (ax25_parms.values[AX25_VALUES_T2] < 1)
-				return -EINVAL;
-			if (ax25_parms.values[AX25_VALUES_T3] < 1)
-				return -EINVAL;
-			if (ax25_parms.values[AX25_VALUES_IDLE] > 100)
-				return -EINVAL;
-			if (ax25_parms.values[AX25_VALUES_N2] < 1 ||
-			    ax25_parms.values[AX25_VALUES_N2] > 31)
-				return -EINVAL;
-			if (ax25_parms.values[AX25_VALUES_PACLEN] < 22)
-				return -EINVAL;
-			if ((ax25_parms.values[AX25_VALUES_DIGI] &
-			    ~(AX25_DIGI_INBAND | AX25_DIGI_XBAND)) != 0)
-				return -EINVAL;
-			if (ax25_parms.values[AX25_VALUES_IPMAXQUEUE] < 1)
-				return -EINVAL;
-			memcpy(ax25_dev->values, ax25_parms.values, AX25_MAX_VALUES * sizeof(short));
-			ax25_dev->values[AX25_VALUES_T1] *= PR_SLOWHZ;
-			ax25_dev->values[AX25_VALUES_T1] /= 2;
-			ax25_dev->values[AX25_VALUES_T2] *= PR_SLOWHZ;
-			ax25_dev->values[AX25_VALUES_T3] *= PR_SLOWHZ;
-			ax25_dev->values[AX25_VALUES_IDLE] *= PR_SLOWHZ * 60;
-			break;
+	ax25_unregister_sysctl();
 
-		case SIOCAX25GETPARMS:
-			if ((err = verify_area(VERIFY_WRITE, arg, sizeof(struct ax25_parms_struct))) != 0)
-				return err;
-			copy_from_user(&ax25_parms, arg, sizeof(ax25_parms));
-			if ((dev = ax25rtr_get_dev(&ax25_parms.port_addr)) == NULL)
-				return -EINVAL;
-			if ((ax25_dev = ax25_dev_get_dev(dev)) == NULL)
-				return -EINVAL;
-			memcpy(ax25_parms.values, ax25_dev->values, AX25_MAX_VALUES * sizeof(short));
-			ax25_parms.values[AX25_VALUES_T1] *= 2;
-			ax25_parms.values[AX25_VALUES_T1] /= PR_SLOWHZ;
-			ax25_parms.values[AX25_VALUES_T2] /= PR_SLOWHZ;
-			ax25_parms.values[AX25_VALUES_T3] /= PR_SLOWHZ;
-			ax25_parms.values[AX25_VALUES_IDLE] /= PR_SLOWHZ * 60;
-			copy_to_user(arg, &ax25_parms, sizeof(ax25_parms));
-			break;
-	}
+	for (i = 0; i < AX25_MAX_DEVICES; i++)
+		if (ax25_device[i].dev != NULL && ax25_device[i].dev == dev)
+			ax25_device[i].dev = NULL;
 
-	return 0;
+	ax25_register_sysctl();
 }
+      
+#ifdef MODULE
 
-#ifdef CONFIG_BPQETHER
-static struct ax25_bpqdev {
-	struct ax25_bpqdev *next;
-	struct device *dev;
-	ax25_address callsign;
-} *ax25_bpqdev = NULL;
-
-int ax25_bpq_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
+/*
+ *    Free all memory associated with routing and device structures.
+ */
+void ax25_rt_free(void)
 {
-	struct ax25_bpqdev *bpqdev;
-	int len     = 0;
-	off_t pos   = 0;
-	off_t begin = 0;
+	struct ax25_route *s, *ax25_rt = ax25_route;
   
-	cli();
-
-	len += sprintf(buffer, "dev  callsign\n");
-
-	for (bpqdev = ax25_bpqdev; bpqdev != NULL; bpqdev = bpqdev->next) {
-		len += sprintf(buffer + len, "%-4s %-9s\n",
-			bpqdev->dev ? bpqdev->dev->name : "???",
-			ax2asc(&bpqdev->callsign));
-
-		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;
-} 
-
-ax25_address *ax25_bpq_get_addr(struct device *dev)
-{
-	struct ax25_bpqdev *bpqdev;
-	
-	for (bpqdev = ax25_bpqdev; bpqdev != NULL; bpqdev = bpqdev->next)
-		if (bpqdev->dev == dev)
-			return &bpqdev->callsign;
-
-	return NULL;
-}
+	while (ax25_rt != NULL) {
+		s       = ax25_rt;
+		ax25_rt = ax25_rt->next;
 
-int ax25_bpq_ioctl(unsigned int cmd, void *arg)
-{
-	unsigned long flags;
-	struct ax25_bpqdev *bpqdev;
-	struct ax25_bpqaddr_struct bpqaddr;
-	struct device *dev;
-	int err;
+		if (s->digipeat != NULL)
+			kfree_s(s->digipeat, sizeof(ax25_digi));
 
-	switch (cmd) {
-		case SIOCAX25BPQADDR:
-			if ((err = verify_area(VERIFY_READ, arg, sizeof(bpqaddr))) != 0)
-				return err;
-			copy_from_user(&bpqaddr, arg, sizeof(bpqaddr));
-			if ((dev = dev_get(bpqaddr.dev)) == NULL)
-				return -EINVAL;
-			if (dev->type != ARPHRD_ETHER)
-				return -EINVAL;
-			for (bpqdev = ax25_bpqdev; bpqdev != NULL; bpqdev = bpqdev->next) {
-				if (bpqdev->dev == dev) {
-					bpqdev->callsign = bpqaddr.addr;
-					return 0;
-				}
-			}
-			if ((bpqdev = (struct ax25_bpqdev *)kmalloc(sizeof(struct ax25_bpqdev), GFP_ATOMIC)) == NULL)
-				return -ENOMEM;
-			bpqdev->dev      = dev;
-			bpqdev->callsign = bpqaddr.addr;
-			save_flags(flags);
-			cli();
-			bpqdev->next = ax25_bpqdev;
-			ax25_bpqdev  = bpqdev;
-			restore_flags(flags);
-			break;
-			
-		default:
-			return -EINVAL;
+		kfree_s(s, sizeof(struct ax25_route));
 	}
-
-	return 0;
 }
 
 #endif
 
 #endif
+            

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov