patch-2.0.35 linux/net/ax25/af_ax25.c

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

diff -u --recursive --new-file v2.0.34/linux/net/ax25/af_ax25.c linux/net/ax25/af_ax25.c
@@ -1,8 +1,5 @@
 /*
- *	AX.25 release 032
- *
- *	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. 
+ *	AX.25 release 035
  *
  *	This code REQUIRES 1.2.1 or higher/ NET3.029
  *
@@ -81,16 +78,23 @@
  *      AX.25 032	Joerg(DL1BKE)		Fixed DAMA timeout error.
  *						ax25_send_frame() limits the number of enqueued
  *						datagrams per socket.
- *			Jonathan(G4KLX)		Remove auto-router.
+ *	AX.25 033	Jonathan(G4KLX)		Removed auto-router.
+ *			Hans(PE1AYX)		Converted to Module.
+ *			Joerg(DL1BKE)		Moved BPQ Ethernet to seperate driver.
+ *						Fixed 2.0.x specific IP over AX.25 problem.
+ *	AX.25 035	Frederic(F1OAT)		Support for pseudo-digipeating.
+ *			Jonathan(G4KLX)		Support for packet forwarding.
+ *			Jonathan(G4KLX)		Fix wildcard listening parameter setting.
  *
  *	To do:
  *		Restructure the ax25_rcv code to be cleaner/faster and
  *		copy only when needed.
  *		Consider better arbitrary protocol support.
  */
- 
+
 #include <linux/config.h>
-#ifdef CONFIG_AX25
+#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
+#include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/socket.h>
@@ -143,14 +147,14 @@
 
 		if (c != ' ') *s++ = c;
 	}
-	
+
 	*s++ = '-';
 
 	if ((n = ((a->ax25_call[6] >> 1) & 0x0F)) > 9) {
 		*s++ = '1';
 		n -= 10;
 	}
-	
+
 	*s++ = n + '0';
 	*s++ = '\0';
 
@@ -162,6 +166,42 @@
 }
 
 /*
+ *	ascii -> ax25 conversion
+ */
+ax25_address *asc2ax(char *callsign)
+{
+	static ax25_address addr;
+	char *s;
+	int n;
+
+	for (s = callsign, n = 0; n < 6; n++) {
+		if (*s != '\0' && *s != '-')
+			addr.ax25_call[n] = *s++;
+		else
+			addr.ax25_call[n] = ' ';
+		addr.ax25_call[n] <<= 1;
+		addr.ax25_call[n] &= 0xFE;
+	}
+
+	if (*s++ == '\0') {
+		addr.ax25_call[6] = 0x00;
+		return &addr;
+	}
+
+	addr.ax25_call[6] = *s++ - '0';
+
+	if (*s != '\0') {
+		addr.ax25_call[6] *= 10;
+		addr.ax25_call[6] += *s++ - '0';
+	}
+
+	addr.ax25_call[6] <<= 1;
+	addr.ax25_call[6] &= 0x1E;
+
+	return &addr;
+}
+
+/*
  *	Compare two ax.25 addresses
  */
 int ax25cmp(ax25_address *a, ax25_address *b)
@@ -181,13 +221,49 @@
 }
 
 /*
+ *	Compare two AX.25 digipeater paths.
+ */
+static int ax25digicmp(ax25_digi *digi1, ax25_digi *digi2)
+{
+	int i;
+
+	if (digi1->ndigi != digi2->ndigi)
+		return 1;
+
+	if (digi1->lastrepeat != digi2->lastrepeat)
+		return 1;
+
+	for (i = 0; i < digi1->ndigi; i++)
+		if (ax25cmp(&digi1->calls[i], &digi2->calls[i]) != 0)
+			return 1;
+
+	return 0;
+}
+
+/*
+ *	Free an allocated ax25 control block. This is done to centralise
+ *	the MOD count code.
+ */
+static void ax25_free_cb(ax25_cb *ax25)
+{
+	if (ax25->digipeat != NULL) {
+		kfree_s(ax25->digipeat, sizeof(ax25_digi));
+		ax25->digipeat = NULL;
+	}
+
+	kfree_s(ax25, sizeof(ax25_cb));
+
+	MOD_DEC_USE_COUNT;
+}
+
+/*
  *	Socket removal during an interrupt is now safe.
  */
 static void ax25_remove_socket(ax25_cb *ax25)
 {
 	ax25_cb *s;
 	unsigned long flags;
-	
+
 	save_flags(flags);
 	cli();
 
@@ -216,18 +292,11 @@
 static void ax25_kill_by_device(struct device *dev)
 {
 	ax25_cb *s;
-	
+
 	for (s = ax25_list; s != NULL; s = s->next) {
 		if (s->device == dev) {
-			s->state  = AX25_STATE_0;
 			s->device = NULL;
-			if (s->sk != NULL) {
-				s->sk->state = TCP_CLOSE;
-				s->sk->err   = ENETUNREACH;
-				if (!s->sk->dead)
-					s->sk->state_change(s->sk);
-				s->sk->dead  = 1;
-			}
+			ax25_disconnect(s, ENETUNREACH);
 		}
 	}
 }
@@ -239,6 +308,10 @@
 {
 	struct device *dev = (struct device *)ptr;
 
+	/* Reject non AX.25 devices */
+	if (dev->type != ARPHRD_AX25)
+		return NOTIFY_DONE;
+
 	switch (event) {
 		case NETDEV_UP:
 			ax25_dev_device_up(dev);
@@ -275,7 +348,7 @@
  *	Find a socket that wants to accept the SABM we have just
  *	received.
  */
-static struct sock *ax25_find_listener(ax25_address *addr, struct device *dev, int type)
+static struct sock *ax25_find_listener(ax25_address *addr, int digi, struct device *dev, int type)
 {
 	unsigned long flags;
 	ax25_cb *s;
@@ -284,6 +357,8 @@
 	cli();
 
 	for (s = ax25_list; s != NULL; s = s->next) {
+		if ((s->iamdigi && !digi) || (!s->iamdigi && digi))
+			continue;
 		if (s->sk != NULL && ax25cmp(&s->source_addr, addr) == 0 && s->sk->type == type && s->sk->state == TCP_LISTEN) {
 			/* If device is null we match any device */
 			if (s->device == NULL || s->device == dev) {
@@ -324,7 +399,7 @@
  *	Find an AX.25 control block given both ends. It will only pick up
  *	floating AX.25 control blocks or non Raw socket bound control blocks.
  */
-static ax25_cb *ax25_find_cb(ax25_address *my_addr, ax25_address *dest_addr, struct device *dev)
+ax25_cb *ax25_find_cb(ax25_address *src_addr, ax25_address *dest_addr, ax25_digi *digi, struct device *dev)
 {
 	ax25_cb *s;
 	unsigned long flags;
@@ -335,7 +410,16 @@
 	for (s = ax25_list; s != NULL; s = s->next) {
 		if (s->sk != NULL && s->sk->type != SOCK_SEQPACKET)
 			continue;
-		if (ax25cmp(&s->source_addr, my_addr) == 0 && ax25cmp(&s->dest_addr, dest_addr) == 0 && s->device == dev) {
+		if (ax25cmp(&s->source_addr, src_addr) == 0 && ax25cmp(&s->dest_addr, dest_addr) == 0 && s->device == dev) {
+			if (digi != NULL && digi->ndigi != 0) {
+				if (s->digipeat == NULL)
+					continue;
+				if (ax25digicmp(s->digipeat, digi) != 0)
+					continue;
+			} else {
+				if (s->digipeat != NULL && s->digipeat->ndigi != 0)
+					continue;
+			}
 			restore_flags(flags);
 			return s;
 		}
@@ -372,22 +456,19 @@
 static void ax25_send_to_raw(struct sock *sk, struct sk_buff *skb, int proto)
 {
 	struct sk_buff *copy;
-	
+
 	while (sk != NULL) {
 		if (sk->type == SOCK_RAW && sk->protocol == proto && sk->rmem_alloc <= sk->rcvbuf) {
 			if ((copy = skb_clone(skb, GFP_ATOMIC)) == NULL)
 				return;
 
-			copy->sk = sk;
-			atomic_add(copy->truesize, &sk->rmem_alloc);
-			skb_queue_tail(&sk->receive_queue, copy);
-			if (!sk->dead)
-				sk->data_ready(sk, skb->len);
+			if (sock_queue_rcv_skb(sk, copy) != 0)
+				kfree_skb(copy, FREE_READ);
 		}
 
 		sk = sk->next;
 	}
-}	
+}
 
 /*
  *	Deferred destroy.
@@ -412,49 +493,40 @@
 {
 	struct sk_buff *skb;
 	unsigned long flags;
-	
+
 	save_flags(flags);
 	cli();
-	
+
 	del_timer(&ax25->timer);
-	
+
 	ax25_remove_socket(ax25);
 	ax25_clear_queues(ax25);	/* Flush the queues */
-	
+
 	if (ax25->sk != NULL) {
 		while ((skb = skb_dequeue(&ax25->sk->receive_queue)) != NULL) {
 			if (skb->sk != ax25->sk) {			/* A pending connection */
 				skb->sk->dead = 1;	/* Queue the unaccepted socket for death */
-				ax25_set_timer(skb->sk->ax25);
-				skb->sk->ax25->state = AX25_STATE_0;
+				ax25_set_timer(skb->sk->protinfo.ax25);
+				skb->sk->protinfo.ax25->state = AX25_STATE_0;
 			}
 
 			kfree_skb(skb, FREE_READ);
 		}
 	}
-	
+
 	if (ax25->sk != NULL) {
-		if (ax25->sk->wmem_alloc || ax25->sk->rmem_alloc) { /* Defer: outstanding buffers */
+		if (ax25->sk->wmem_alloc != 0 || ax25->sk->rmem_alloc != 0) {	/* Defer: outstanding buffers */
 			init_timer(&ax25->timer);
 			ax25->timer.expires  = jiffies + 10 * HZ;
 			ax25->timer.function = ax25_destroy_timer;
 			ax25->timer.data     = (unsigned long)ax25;
 			add_timer(&ax25->timer);
 		} else {
-			if (ax25->digipeat != NULL) {
-				kfree_s(ax25->digipeat, sizeof(ax25_digi));
-				ax25->digipeat = NULL;
-			}
-		
 			sk_free(ax25->sk);
-			kfree_s(ax25, sizeof(*ax25));
+			ax25_free_cb(ax25);
 		}
 	} else {
-		if (ax25->digipeat != NULL) {
-			kfree_s(ax25->digipeat, sizeof(ax25_digi));
-			ax25->digipeat = NULL;
-		}	
-		kfree_s(ax25, sizeof(*ax25));
+		ax25_free_cb(ax25);
 	}
 
 	restore_flags(flags);
@@ -471,7 +543,7 @@
 ax25_address *ax25_findbyuid(uid_t uid)
 {
 	ax25_uid_assoc *a;
-	
+
 	for (a = ax25_uid_list; a != NULL; a = a->next) {
 		if (a->uid == uid)
 			return &a->call;
@@ -483,7 +555,7 @@
 static int ax25_uid_ioctl(int cmd, struct sockaddr_ax25 *sax)
 {
 	ax25_uid_assoc *a;
-	
+
 	switch (cmd) {
 		case SIOCAX25GETUID:
 			for (a = ax25_uid_list; a != NULL; a = a->next) {
@@ -493,10 +565,12 @@
 			return -ENOENT;
 
 		case SIOCAX25ADDUID:
-			if(!suser())
+			if (!suser())
 				return -EPERM;
 			if (ax25_findbyuid(sax->sax25_uid))
 				return -EEXIST;
+			if (sax->sax25_uid == 0)
+				return -EINVAL;
 			a = (ax25_uid_assoc *)kmalloc(sizeof(*a), GFP_KERNEL);
 			if (a == NULL)
 				return -ENOMEM;
@@ -508,8 +582,8 @@
 
 		case SIOCAX25DELUID: {
 			ax25_uid_assoc **l;
-			
-			if(!suser())
+
+			if (!suser())
 				return -EPERM;
 			l = &ax25_uid_list;
 			while ((*l) != NULL) {
@@ -519,12 +593,12 @@
 					kfree_s(a, sizeof(*a));
 					return 0;
 				}
-				
+
 				l = &((*l)->next);
 			}
 			return -ENOENT;
 		}
-		
+
 		default:
 			return -EINVAL;
 	}
@@ -544,55 +618,41 @@
 	ax25_cb *ax25;
 	unsigned long flags;
 	int err;
-	
+
 	if ((err = verify_area(VERIFY_READ, arg, sizeof(ax25_ctl))) != 0)
 		return err;
 
 	memcpy_fromfs(&ax25_ctl, arg, sizeof(ax25_ctl));
-	
+
 	if ((dev = ax25rtr_get_dev(&ax25_ctl.port_addr)) == NULL)
 		return -ENODEV;
 
-	if ((ax25 = ax25_find_cb(&ax25_ctl.source_addr, &ax25_ctl.dest_addr, dev)) == NULL)
+	if ((ax25 = ax25_find_cb(&ax25_ctl.source_addr, &ax25_ctl.dest_addr, NULL, dev)) == NULL)
 		return -ENOTCONN;
 
 	switch (ax25_ctl.cmd) {
 		case AX25_KILL:
-#ifdef CONFIG_NETROM
-			nr_link_failed(&ax25->dest_addr, ax25->device);
-#endif
-			ax25_clear_queues(ax25);
-			ax25_send_control(ax25, DISC, POLLON, C_COMMAND);
-				
-			ax25->state = AX25_STATE_0;
-			if (ax25->sk != NULL) {
-				ax25->sk->state = TCP_CLOSE;
-				ax25->sk->err   = ENETRESET;
-				if (!ax25->sk->dead)
-					ax25->sk->state_change(ax25->sk);
-				ax25->sk->dead  = 1;
-			}
-
-			ax25_dama_off(ax25);
+			ax25_send_control(ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
+			ax25_disconnect(ax25, ENETRESET);
 			ax25_set_timer(ax25);
 	  		break;
 
 	  	case AX25_WINDOW:
-	  		if (ax25->modulus == MODULUS) {
-	  			if (ax25_ctl.arg < 1 || ax25_ctl.arg > 7) 
+	  		if (ax25->modulus == AX25_MODULUS) {
+	  			if (ax25_ctl.arg < 1 || ax25_ctl.arg > 7)
 	  				return -EINVAL;
 	  		} else {
-	  			if (ax25_ctl.arg < 1 || ax25_ctl.arg > 63) 
+	  			if (ax25_ctl.arg < 1 || ax25_ctl.arg > 63)
 	  				return -EINVAL;
 	  		}
 	  		ax25->window = ax25_ctl.arg;
 	  		break;
 
 	  	case AX25_T1:
-  			if (ax25_ctl.arg < 1) 
+  			if (ax25_ctl.arg < 1)
   				return -EINVAL;
-  			ax25->rtt = (ax25_ctl.arg * PR_SLOWHZ) / 2;
-  			ax25->t1 = ax25_ctl.arg * PR_SLOWHZ;
+  			ax25->rtt = (ax25_ctl.arg * AX25_SLOWHZ) / 2;
+  			ax25->t1  = ax25_ctl.arg * AX25_SLOWHZ;
   			save_flags(flags); cli();
   			if (ax25->t1timer > ax25->t1)
   				ax25->t1timer = ax25->t1;
@@ -600,66 +660,101 @@
   			break;
 
 	  	case AX25_T2:
-	  		if (ax25_ctl.arg < 1) 
+	  		if (ax25_ctl.arg < 1)
 	  			return -EINVAL;
 	  		save_flags(flags); cli();
-	  		ax25->t2 = ax25_ctl.arg * PR_SLOWHZ;
+	  		ax25->t2 = ax25_ctl.arg * AX25_SLOWHZ;
 	  		if (ax25->t2timer > ax25->t2)
 	  			ax25->t2timer = ax25->t2;
 	  		restore_flags(flags);
 	  		break;
 
 	  	case AX25_N2:
-	  		if (ax25_ctl.arg < 1 || ax25_ctl.arg > 31) 
+	  		if (ax25_ctl.arg < 1 || ax25_ctl.arg > 31)
 	  			return -EINVAL;
 	  		ax25->n2count = 0;
 	  		ax25->n2 = ax25_ctl.arg;
 	  		break;
 
 	  	case AX25_T3:
-	  		if (ax25_ctl.arg < 0) 
+	  		if (ax25_ctl.arg < 0)
 	  			return -EINVAL;
 	  		save_flags(flags); cli();
-	  		ax25->t3 = ax25_ctl.arg * PR_SLOWHZ;
+	  		ax25->t3 = ax25_ctl.arg * AX25_SLOWHZ;
 	  		if (ax25->t3timer != 0)
 	  			ax25->t3timer = ax25->t3;
 	  		restore_flags(flags);
 	  		break;
 
 	  	case AX25_IDLE:
-	  		if (ax25_ctl.arg < 0) 
+	  		if (ax25_ctl.arg < 0)
 	  			return -EINVAL;
 			save_flags(flags); cli();
-	  		ax25->idle = ax25_ctl.arg * PR_SLOWHZ * 60;
+	  		ax25->idle = ax25_ctl.arg * AX25_SLOWHZ * 60;
 	  		if (ax25->idletimer != 0)
 	  			ax25->idletimer = ax25->idle;
 	  		restore_flags(flags);
 	  		break;
 
 	  	case AX25_PACLEN:
-	  		if (ax25_ctl.arg < 16 || ax25_ctl.arg > 65535) 
+	  		if (ax25_ctl.arg < 16 || ax25_ctl.arg > 65535)
 	  			return -EINVAL;
-#if 0
-	  		if (ax25_ctl.arg > 256) /* we probably want this */
-	  			printk(KERN_WARNING "ax25_ctl_ioctl: Warning --- huge paclen %d\n", (int)ax25_ctl.arg);
-#endif	  			
 	  		ax25->paclen = ax25_ctl.arg;
 	  		break;
 
-	  	case AX25_IPMAXQUEUE:
-	  		if (ax25_ctl.arg < 1)
-	  			return -EINVAL;
-	  		ax25->maxqueue = ax25_ctl.arg;
-	  		break;
-
 	  	default:
 	  		return -EINVAL;
 	  }
-	  
+
 	  return 0;
 }
 
 /*
+ *	Fill in a created AX.25 created control block with the default
+ *	values for a particular device.
+ */
+static void ax25_fillin_cb(ax25_cb *ax25, struct device *dev)
+{
+	ax25->device = dev;
+
+	if (dev != NULL) {
+		ax25->rtt     = ax25_dev_get_value(dev, AX25_VALUES_T1) / 2;
+		ax25->t1      = ax25_dev_get_value(dev, AX25_VALUES_T1);
+		ax25->t2      = ax25_dev_get_value(dev, AX25_VALUES_T2);
+		ax25->t3      = ax25_dev_get_value(dev, AX25_VALUES_T3);
+		ax25->n2      = ax25_dev_get_value(dev, AX25_VALUES_N2);
+		ax25->paclen  = ax25_dev_get_value(dev, AX25_VALUES_PACLEN);
+		ax25->idle    = ax25_dev_get_value(dev, AX25_VALUES_IDLE);
+		ax25->backoff = ax25_dev_get_value(dev, AX25_VALUES_BACKOFF);
+
+		if (ax25_dev_get_value(dev, AX25_VALUES_AXDEFMODE)) {
+			ax25->modulus = AX25_EMODULUS;
+			ax25->window  = ax25_dev_get_value(dev, AX25_VALUES_EWINDOW);
+		} else {
+			ax25->modulus = AX25_MODULUS;
+			ax25->window  = ax25_dev_get_value(dev, AX25_VALUES_WINDOW);
+		}
+	} else {
+		ax25->rtt     = AX25_DEF_T1 / 2;
+		ax25->t1      = AX25_DEF_T1;
+		ax25->t2      = AX25_DEF_T2;
+		ax25->t3      = AX25_DEF_T3;
+		ax25->n2      = AX25_DEF_N2;
+		ax25->paclen  = AX25_DEF_PACLEN;
+		ax25->idle    = AX25_DEF_IDLE;
+		ax25->backoff = AX25_DEF_BACKOFF;
+
+		if (AX25_DEF_AXDEFMODE) {
+			ax25->modulus = AX25_EMODULUS;
+			ax25->window  = AX25_DEF_EWINDOW;
+		} else {
+			ax25->modulus = AX25_MODULUS;
+			ax25->window  = AX25_DEF_WINDOW;
+		}
+	}
+}
+
+/*
  * Create an empty AX.25 control block.
  */
 static ax25_cb *ax25_create_cb(void)
@@ -669,6 +764,10 @@
 	if ((ax25 = (ax25_cb *)kmalloc(sizeof(*ax25), GFP_ATOMIC)) == NULL)
 		return NULL;
 
+	MOD_INC_USE_COUNT;
+
+	memset(ax25, 0x00, sizeof(*ax25));
+
 	skb_queue_head_init(&ax25->write_queue);
 	skb_queue_head_init(&ax25->frag_queue);
 	skb_queue_head_init(&ax25->ack_queue);
@@ -676,47 +775,9 @@
 
 	init_timer(&ax25->timer);
 
-	ax25->dama_slave = 0;
-
-	ax25->rtt     = (AX25_DEF_T1 * PR_SLOWHZ) / 2;
-	ax25->t1      = AX25_DEF_T1 * PR_SLOWHZ;
-	ax25->t2      = AX25_DEF_T2 * PR_SLOWHZ;
-	ax25->t3      = AX25_DEF_T3 * PR_SLOWHZ;
-	ax25->n2      = AX25_DEF_N2;
-	ax25->paclen  = AX25_DEF_PACLEN;
-	ax25->maxqueue= AX25_DEF_IPMAXQUEUE;
-	ax25->idle    = AX25_DEF_IDLE;
-
-	ax25->modulus   = AX25_DEF_AXDEFMODE;
-	ax25->fragno    = 0;
-	ax25->fraglen   = 0;
-	ax25->hdrincl   = 0;
-	ax25->backoff   = AX25_DEF_BACKOFF == 'E';
-	ax25->condition = 0x00;
-	ax25->t1timer   = 0;
-	ax25->t2timer   = 0;
-	ax25->t3timer   = 0;
-	ax25->n2count   = 0;
-	ax25->idletimer = 0;
-
-	ax25->va      = 0;
-	ax25->vr      = 0;
-	ax25->vs      = 0;
-
-	if (AX25_DEF_AXDEFMODE == EMODULUS) {
-		ax25->window = AX25_DEF_EWINDOW;
-	} else {
-		ax25->window = AX25_DEF_WINDOW;
-	}
-
-	ax25->device   = NULL;
-	ax25->digipeat = NULL;
-	ax25->sk       = NULL;
-
-	ax25->state    = AX25_STATE_0;
+	ax25_fillin_cb(ax25, NULL);
 
-	memset(&ax25->dest_addr,   '\0', AX25_ADDR_LEN);
-	memset(&ax25->source_addr, '\0', AX25_ADDR_LEN);
+	ax25->state = AX25_STATE_0;
 
 	return ax25;
 }
@@ -731,75 +792,35 @@
 {
 	ax25_cb *ax25;
 	int count = 0;
-	
+
 	for (ax25 = ax25_list; ax25 != NULL; ax25 = ax25->next) {
 		if (ax25->device == dev && ax25->dama_slave) {
 			count++;
 			break;
 		}
 	}
-		
-	return count;
-}
 
-/*
- *	Fill in a created AX.25 created control block with the default
- *	values for a particular device.
- */
-static void ax25_fillin_cb(ax25_cb *ax25, struct device *dev)
-{
-	ax25->device  = dev;
-
-	ax25->rtt      = ax25_dev_get_value(dev, AX25_VALUES_T1);
-	ax25->t1       = ax25_dev_get_value(dev, AX25_VALUES_T1);
-	ax25->t2       = ax25_dev_get_value(dev, AX25_VALUES_T2);
-	ax25->t3       = ax25_dev_get_value(dev, AX25_VALUES_T3);
-	ax25->n2       = ax25_dev_get_value(dev, AX25_VALUES_N2);
-	ax25->paclen   = ax25_dev_get_value(dev, AX25_VALUES_PACLEN);
-	ax25->maxqueue = ax25_dev_get_value(dev, AX25_VALUES_IPMAXQUEUE);
-	ax25->idle     = ax25_dev_get_value(dev, AX25_VALUES_IDLE);
-
-	ax25->dama_slave = 0;
-
-	ax25->modulus = ax25_dev_get_value(dev, AX25_VALUES_AXDEFMODE);
-
-	if (ax25->modulus == MODULUS) {
-		ax25->window = ax25_dev_get_value(dev, AX25_VALUES_WINDOW);
-	} else {
-		ax25->window = ax25_dev_get_value(dev, AX25_VALUES_EWINDOW);
-	}
-
-	ax25->backoff = ax25_dev_get_value(dev, AX25_VALUES_BACKOFF) == 'E';
+	return count;
 }
 
-int ax25_send_frame(struct sk_buff *skb, ax25_address *src, ax25_address *dest,
+ax25_cb *ax25_send_frame(struct sk_buff *skb, int paclen, ax25_address *src, ax25_address *dest,
 	ax25_digi *digi, struct device *dev)
 {
 	ax25_cb *ax25;
 
-	if (skb == NULL)
-		return 0;
+	if (paclen == 0)
+		paclen = ax25_dev_get_value(dev, AX25_VALUES_PACLEN);
 
 	/*
 	 * Look for an existing connection.
 	 */
-	for (ax25 = ax25_list; ax25 != NULL; ax25 = ax25->next) {
-		if (ax25->sk != NULL && ax25->sk->type != SOCK_SEQPACKET)
-			continue;
-
-		if (ax25cmp(&ax25->source_addr, src) == 0 && ax25cmp(&ax25->dest_addr, dest) == 0 && ax25->device == dev) {
-			if (ax25_queue_length(ax25, skb) > ax25->maxqueue * ax25->window) {
-				kfree_skb(skb, FREE_WRITE);
-			} else {
-				ax25_output(ax25, skb);
-			}
-			ax25->idletimer = ax25->idle;
-			return 1;		/* It already existed */
-		}
+	if ((ax25 = ax25_find_cb(src, dest, digi, dev)) != NULL) {
+		ax25_output(ax25, paclen, skb);
+		return ax25;		/* It already existed */
 	}
 
 	if ((ax25 = ax25_create_cb()) == NULL)
-		return 0;
+		return NULL;
 
 	ax25_fillin_cb(ax25, dev);
 
@@ -808,12 +829,10 @@
 
 	if (digi != NULL) {
 		if ((ax25->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
-			kfree_s(ax25, sizeof(ax25));
-			return 0;
+			ax25_free_cb(ax25);
+			return NULL;
 		}
 		*ax25->digipeat = *digi;
-	} else {
-		ax25_rt_build_path(ax25, dest, dev);
 	}
 
 	if (ax25_dev_is_dama_slave(ax25->device))
@@ -821,19 +840,15 @@
 	else
 		ax25_establish_data_link(ax25);
 
-	/* idle timeouts only for mode vc connections */
-
-	ax25->idletimer = ax25->idle;
-		
 	ax25_insert_socket(ax25);
 
 	ax25->state = AX25_STATE_1;
 
 	ax25_set_timer(ax25);
 
-	ax25_output(ax25, skb);
-			
-	return 1;			/* We had to create it */	
+	ax25_output(ax25, paclen, skb);
+
+	return ax25;			/* We had to create it */
 }
 
 /*
@@ -842,29 +857,11 @@
 struct device *ax25rtr_get_dev(ax25_address *addr)
 {
 	struct device *dev;
-	
-	for (dev = dev_base; dev != NULL; dev = dev->next) {
-		if (dev->flags & IFF_UP) {
-			switch (dev->type) {
-				case ARPHRD_AX25: /* Active kiss ax25 mode */ 
-					if (ax25cmp(addr, (ax25_address *)dev->dev_addr) == 0)
-						return dev;
-					break;
-#ifdef CONFIG_BPQETHER
-				case ARPHRD_ETHER: {
-						ax25_address *dev_addr;
-
-						if ((dev_addr = ax25_bpq_get_addr(dev)) != NULL)
-							if (ax25cmp(addr, dev_addr) == 0)
-								return dev;
-					}
-					break;
-#endif
-				default:
-					break;
-			}
-		}
-	}
+
+	for (dev = dev_base; dev != NULL; dev = dev->next)
+		if ((dev->flags & IFF_UP) && dev->type == ARPHRD_AX25 &&
+		    ax25cmp(addr, (ax25_address *)dev->dev_addr) == 0)
+		     	return dev;
 
 	return NULL;
 }
@@ -873,7 +870,6 @@
  *	Handling for system calls applied via the various interfaces to an
  *	AX25 socket object
  */
- 
 static int ax25_fcntl(struct socket *sock, unsigned int cmd, unsigned long arg)
 {
 	return -EINVAL;
@@ -882,11 +878,9 @@
 static int ax25_setsockopt(struct socket *sock, int level, int optname,
 	char *optval, int optlen)
 {
-	struct sock *sk;
+	struct sock *sk = (struct sock *)sock->data;
 	int err, opt;
 
-	sk = (struct sock *)sock->data;
-	
 	if (level == SOL_SOCKET)
 		return sock_setsockopt(sk, level, optname, optval, optlen);
 
@@ -899,66 +893,73 @@
 	if ((err = verify_area(VERIFY_READ, optval, sizeof(int))) != 0)
 		return err;
 
-	opt = get_fs_long((unsigned long *)optval);
+	opt = get_fs_long((int *)optval);
 
 	switch (optname) {
 		case AX25_WINDOW:
-			if (sk->ax25->modulus == MODULUS) {
+			if (sk->protinfo.ax25->modulus == AX25_MODULUS) {
 				if (opt < 1 || opt > 7)
 					return -EINVAL;
 			} else {
 				if (opt < 1 || opt > 63)
 					return -EINVAL;
 			}
-			sk->ax25->window = opt;
+			sk->protinfo.ax25->window = opt;
 			return 0;
 
 		case AX25_T1:
 			if (opt < 1)
 				return -EINVAL;
-			sk->ax25->rtt = (opt * PR_SLOWHZ) / 2;
+			sk->protinfo.ax25->rtt = (opt * AX25_SLOWHZ) / 2;
+			sk->protinfo.ax25->t1  = opt * AX25_SLOWHZ;
 			return 0;
 
 		case AX25_T2:
 			if (opt < 1)
 				return -EINVAL;
-			sk->ax25->t2 = opt * PR_SLOWHZ;
+			sk->protinfo.ax25->t2 = opt * AX25_SLOWHZ;
 			return 0;
 
 		case AX25_N2:
 			if (opt < 1 || opt > 31)
 				return -EINVAL;
-			sk->ax25->n2 = opt;
+			sk->protinfo.ax25->n2 = opt;
 			return 0;
 
 		case AX25_T3:
 			if (opt < 1)
 				return -EINVAL;
-			sk->ax25->t3 = opt * PR_SLOWHZ;
+			sk->protinfo.ax25->t3 = opt * AX25_SLOWHZ;
 			return 0;
-			
+
 		case AX25_IDLE:
 			if (opt < 0)
 				return -EINVAL;
-			sk->ax25->idle = opt * PR_SLOWHZ * 60;
+			sk->protinfo.ax25->idle = opt * AX25_SLOWHZ * 60;
 			return 0;
 
 		case AX25_BACKOFF:
-			sk->ax25->backoff = opt ? 1 : 0;
+			if (opt < 0 || opt > 2)
+				return -EINVAL;
+			sk->protinfo.ax25->backoff = opt;
 			return 0;
 
 		case AX25_EXTSEQ:
-			sk->ax25->modulus = opt ? EMODULUS : MODULUS;
+			sk->protinfo.ax25->modulus = opt ? AX25_EMODULUS : AX25_MODULUS;
 			return 0;
 
-		case AX25_HDRINCL:
-			sk->ax25->hdrincl = opt ? 1 : 0;
+		case AX25_PIDINCL:
+			sk->protinfo.ax25->pidincl = opt ? 1 : 0;
 			return 0;
-			
+
+		case AX25_IAMDIGI:
+			sk->protinfo.ax25->iamdigi = opt ? 1 : 0;
+			return 0;
+
 		case AX25_PACLEN:
 			if (opt < 16 || opt > 65535)
 				return -EINVAL;
-			sk->ax25->paclen = opt;
+			sk->protinfo.ax25->paclen = opt;
 			return 0;
 
 		default:
@@ -969,57 +970,59 @@
 static int ax25_getsockopt(struct socket *sock, int level, int optname,
 	char *optval, int *optlen)
 {
-	struct sock *sk;
+	struct sock *sk = (struct sock *)sock->data;
 	int val = 0;
-	int err; 
+	int err;
 
-	sk = (struct sock *)sock->data;
-	
 	if (level == SOL_SOCKET)
 		return sock_getsockopt(sk, level, optname, optval, optlen);
-	
+
 	if (level != SOL_AX25)
 		return -EOPNOTSUPP;
 
 	switch (optname) {
 		case AX25_WINDOW:
-			val = sk->ax25->window;
+			val = sk->protinfo.ax25->window;
 			break;
 
 		case AX25_T1:
-			val = (sk->ax25->t1 * 2) / PR_SLOWHZ;
+			val = sk->protinfo.ax25->t1 / AX25_SLOWHZ;
 			break;
 
 		case AX25_T2:
-			val = sk->ax25->t2 / PR_SLOWHZ;
+			val = sk->protinfo.ax25->t2 / AX25_SLOWHZ;
 			break;
 
 		case AX25_N2:
-			val = sk->ax25->n2;
+			val = sk->protinfo.ax25->n2;
 			break;
 
 		case AX25_T3:
-			val = sk->ax25->t3 / PR_SLOWHZ;
+			val = sk->protinfo.ax25->t3 / AX25_SLOWHZ;
 			break;
-			
+
 		case AX25_IDLE:
-			val = sk->ax25->idle / (PR_SLOWHZ * 60);
+			val = sk->protinfo.ax25->idle / (AX25_SLOWHZ * 60);
 			break;
 
 		case AX25_BACKOFF:
-			val = sk->ax25->backoff;
+			val = sk->protinfo.ax25->backoff;
 			break;
 
 		case AX25_EXTSEQ:
-			val = (sk->ax25->modulus == EMODULUS);
+			val = (sk->protinfo.ax25->modulus == AX25_EMODULUS);
 			break;
 
-		case AX25_HDRINCL:
-			val = sk->ax25->hdrincl;
+		case AX25_PIDINCL:
+			val = sk->protinfo.ax25->pidincl;
 			break;
-			
+
+		case AX25_IAMDIGI:
+			val = sk->protinfo.ax25->iamdigi;
+			break;
+
 		case AX25_PACLEN:
-			val = sk->ax25->paclen;
+			val = sk->protinfo.ax25->paclen;
 			break;
 
 		default:
@@ -1088,7 +1091,20 @@
 #ifdef CONFIG_NETROM
 				case AX25_P_NETROM:
 #endif
+#ifdef CONFIG_ROSE
+				case AX25_P_ROSE:
+#endif
 					return -ESOCKTNOSUPPORT;
+#ifdef CONFIG_NETROM_MODULE
+				case AX25_P_NETROM:
+					if (ax25_protocol_is_registered(AX25_P_NETROM))
+						return -ESOCKTNOSUPPORT;
+#endif
+#ifdef CONFIG_ROSE_MODULE
+				case AX25_P_ROSE:
+					if (ax25_protocol_is_registered(AX25_P_ROSE))
+						return -ESOCKTNOSUPPORT;
+#endif
 				default:
 					break;
 			}
@@ -1133,9 +1149,9 @@
 		sk->sleep  = sock->wait;
 	}
 
-	ax25->sk = sk;
-	sk->ax25 = ax25;
-	
+	ax25->sk          = sk;
+	sk->protinfo.ax25 = ax25;
+
 	return 0;
 }
 
@@ -1164,7 +1180,7 @@
 			break;
 		default:
 			sk_free(sk);
-			kfree_s((void *)ax25, sizeof(*ax25));
+			ax25_free_cb(ax25);
 			return NULL;
 	}
 
@@ -1179,7 +1195,6 @@
 	sk->sndbuf      = osk->sndbuf;
 	sk->debug       = osk->debug;
 	sk->state       = TCP_ESTABLISHED;
-	sk->window      = osk->window;
 	sk->mtu         = osk->mtu;
 	sk->sleep       = osk->sleep;
 	sk->zapped      = osk->zapped;
@@ -1189,34 +1204,33 @@
 	sk->write_space  = def_callback1;
 	sk->error_report = def_callback1;
 
-	ax25->modulus = osk->ax25->modulus;
-	ax25->backoff = osk->ax25->backoff;
-	ax25->hdrincl = osk->ax25->hdrincl;
-	ax25->rtt     = osk->ax25->rtt;
-	ax25->t1      = osk->ax25->t1;
-	ax25->t2      = osk->ax25->t2;
-	ax25->t3      = osk->ax25->t3;
-	ax25->n2      = osk->ax25->n2;
-	ax25->idle    = osk->ax25->idle;
-	ax25->paclen  = osk->ax25->paclen;
+	ax25->modulus = osk->protinfo.ax25->modulus;
+	ax25->backoff = osk->protinfo.ax25->backoff;
+	ax25->pidincl = osk->protinfo.ax25->pidincl;
+	ax25->iamdigi = osk->protinfo.ax25->iamdigi;
+	ax25->rtt     = osk->protinfo.ax25->rtt;
+	ax25->t1      = osk->protinfo.ax25->t1;
+	ax25->t2      = osk->protinfo.ax25->t2;
+	ax25->t3      = osk->protinfo.ax25->t3;
+	ax25->n2      = osk->protinfo.ax25->n2;
+	ax25->idle    = osk->protinfo.ax25->idle;
+	ax25->paclen  = osk->protinfo.ax25->paclen;
+	ax25->window  = osk->protinfo.ax25->window;
 
-	ax25->window   = osk->ax25->window;
-	ax25->maxqueue = osk->ax25->maxqueue;
+	ax25->source_addr = osk->protinfo.ax25->source_addr;
 
-	ax25->source_addr = osk->ax25->source_addr;
-	
-	if (osk->ax25->digipeat != NULL) {
+	if (osk->protinfo.ax25->digipeat != NULL) {
 		if ((ax25->digipeat = (ax25_digi *)kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
 			sk_free(sk);
-			kfree_s(ax25, sizeof(*ax25));
+			ax25_free_cb(ax25);
 			return NULL;
 		}
-		
-		*ax25->digipeat = *osk->ax25->digipeat;
+
+		*ax25->digipeat = *osk->protinfo.ax25->digipeat;
 	}
 
-	sk->ax25 = ax25;
-	ax25->sk = sk;
+	sk->protinfo.ax25 = ax25;
+	ax25->sk          = sk;
 
 	return sk;
 }
@@ -1225,6 +1239,9 @@
 {
 	struct sock *sk = (struct sock *)oldsock->data;
 
+	if (sk == NULL || newsock == NULL)
+		return -EINVAL;
+
 	return ax25_create(newsock, sk->protocol);
 }
 
@@ -1235,51 +1252,44 @@
 	if (sk == NULL) return 0;
 
 	if (sk->type == SOCK_SEQPACKET) {
-		switch (sk->ax25->state) {
+		switch (sk->protinfo.ax25->state) {
 			case AX25_STATE_0:
-				sk->state       = TCP_CLOSE;
-				sk->state_change(sk);
-				sk->dead        = 1;
-				ax25_destroy_socket(sk->ax25);
+				ax25_disconnect(sk->protinfo.ax25, 0);
+				ax25_destroy_socket(sk->protinfo.ax25);
 				break;
 
 			case AX25_STATE_1:
-				ax25_send_control(sk->ax25, DISC, POLLON, C_COMMAND);
-				sk->ax25->state = AX25_STATE_0;
-				sk->state       = TCP_CLOSE;
-				sk->state_change(sk);
-				sk->dead        = 1;
-				ax25_destroy_socket(sk->ax25);
+				ax25_send_control(sk->protinfo.ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
+				ax25_disconnect(sk->protinfo.ax25, 0);
+				ax25_destroy_socket(sk->protinfo.ax25);
 				break;
 
 			case AX25_STATE_2:
-				if (sk->ax25->dama_slave)
-					ax25_send_control(sk->ax25, DISC, POLLON, C_COMMAND);
+				if (sk->protinfo.ax25->dama_slave)
+					ax25_send_control(sk->protinfo.ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
 				else
-					ax25_send_control(sk->ax25, DM, POLLON, C_RESPONSE);
-				sk->ax25->state = AX25_STATE_0;
-				sk->state       = TCP_CLOSE;
-				sk->state_change(sk);
-				sk->dead        = 1;
-				ax25_destroy_socket(sk->ax25);
-				break;			
+					ax25_send_control(sk->protinfo.ax25, AX25_DM, AX25_POLLON, AX25_RESPONSE);
+				ax25_disconnect(sk->protinfo.ax25, 0);
+				ax25_destroy_socket(sk->protinfo.ax25);
+				break;
 
 			case AX25_STATE_3:
 			case AX25_STATE_4:
-				ax25_clear_queues(sk->ax25);
-				sk->ax25->n2count = 0;
-				if (!sk->ax25->dama_slave) {
-					ax25_send_control(sk->ax25, DISC, POLLON, C_COMMAND);
-					sk->ax25->t3timer = 0;
+				ax25_clear_queues(sk->protinfo.ax25);
+				sk->protinfo.ax25->n2count = 0;
+				if (!sk->protinfo.ax25->dama_slave) {
+					ax25_send_control(sk->protinfo.ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
+					sk->protinfo.ax25->t3timer = 0;
 				} else {
-					sk->ax25->t3timer = sk->ax25->t3;	/* DAMA slave timeout */
+					sk->protinfo.ax25->t3timer = sk->protinfo.ax25->t3;	/* DAMA slave timeout */
 				}
-				sk->ax25->t1timer = sk->ax25->t1 = ax25_calculate_t1(sk->ax25);
-				sk->ax25->state   = AX25_STATE_2;
-				sk->state         = TCP_CLOSE;
+				sk->protinfo.ax25->t1timer = sk->protinfo.ax25->t1 = ax25_calculate_t1(sk->protinfo.ax25);
+				sk->protinfo.ax25->state   = AX25_STATE_2;
+				sk->state                  = TCP_CLOSE;
+				sk->shutdown              |= SEND_SHUTDOWN;
 				sk->state_change(sk);
-				sk->dead          = 1;
-				sk->destroy       = 1;
+				sk->dead                   = 1;
+				sk->destroy                = 1;
 				break;
 
 			default:
@@ -1287,9 +1297,10 @@
 		}
 	} else {
 		sk->state       = TCP_CLOSE;
+		sk->shutdown   |= SEND_SHUTDOWN;
 		sk->state_change(sk);
-		sk->dead = 1;
-		ax25_destroy_socket(sk->ax25);
+		sk->dead        = 1;
+		ax25_destroy_socket(sk->protinfo.ax25);
 	}
 
 	sock->data = NULL;	
@@ -1304,32 +1315,33 @@
  *	BSD 4.4 ADDIFADDR type support. It is however small and trivially backward
  *	compatible 8)
  */
-static int ax25_bind(struct socket *sock, struct sockaddr *uaddr,int addr_len)
+static int ax25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 {
-	struct sock *sk;
+	struct sock *sk = (struct sock *)sock->data;
 	struct full_sockaddr_ax25 *addr = (struct full_sockaddr_ax25 *)uaddr;
 	struct device *dev;
 	ax25_address *call;
-	
-	sk = (struct sock *)sock->data;
-	
+
 	if (sk->zapped == 0)
-		return -EIO;
-		
+		return -EINVAL;
+
 	if (addr_len != sizeof(struct sockaddr_ax25) && addr_len != sizeof(struct full_sockaddr_ax25))
 		return -EINVAL;
 
+	if (addr->fsa_ax25.sax25_family != AF_AX25)
+		return -EINVAL;
+
 	call = ax25_findbyuid(current->euid);
 	if (call == NULL && ax25_uid_policy && !suser())
-		return -EPERM;
-		
+		return -EACCES;
+
 	if (call == NULL)
-		sk->ax25->source_addr = addr->fsa_ax25.sax25_call;
+		sk->protinfo.ax25->source_addr = addr->fsa_ax25.sax25_call;
 	else
-		sk->ax25->source_addr = *call;
+		sk->protinfo.ax25->source_addr = *call;
 
 	if (sk->debug)
-		printk("AX25: source address set to %s\n", ax2asc(&sk->ax25->source_addr));
+		printk("AX25: source address set to %s\n", ax2asc(&sk->protinfo.ax25->source_addr));
 
 	if (addr_len == sizeof(struct full_sockaddr_ax25) && addr->fsa_ax25.sax25_ndigis == 1) {
 		if (ax25cmp(&addr->fsa_digipeater[0], &null_ax25_address) == 0) {
@@ -1355,8 +1367,8 @@
 			printk("AX25: bound to device %s\n", dev->name);
 	}
 
-	ax25_fillin_cb(sk->ax25, dev);
-	ax25_insert_socket(sk->ax25);
+	ax25_fillin_cb(sk->protinfo.ax25, dev);
+	ax25_insert_socket(sk->protinfo.ax25);
 
 	sk->zapped = 0;
 
@@ -1370,53 +1382,61 @@
 	int addr_len, int flags)
 {
 	struct sock *sk = (struct sock *)sock->data;
-	struct sockaddr_ax25 *addr = (struct sockaddr_ax25 *)uaddr;
-	int err;
-	
+	struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)uaddr;
+	ax25_digi *digi = NULL;
+	int ct = 0, err;
+
 	if (sk->state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) {
 		sock->state = SS_CONNECTED;
 		return 0;	/* Connect completed during a ERESTARTSYS event */
 	}
-	
+
 	if (sk->state == TCP_CLOSE && sock->state == SS_CONNECTING) {
 		sock->state = SS_UNCONNECTED;
 		return -ECONNREFUSED;
 	}
-	
+
 	if (sk->state == TCP_ESTABLISHED && sk->type == SOCK_SEQPACKET)
 		return -EISCONN;	/* No reconnect on a seqpacket socket */
-		
-	sk->state   = TCP_CLOSE;	
+
+	sk->state   = TCP_CLOSE;
 	sock->state = SS_UNCONNECTED;
 
 	if (addr_len != sizeof(struct sockaddr_ax25) && addr_len != sizeof(struct full_sockaddr_ax25))
 		return -EINVAL;
 
+	if (fsa->fsa_ax25.sax25_family != AF_AX25)
+		return -EINVAL;
+
+	if (sk->protinfo.ax25->digipeat != NULL) {
+		kfree_s(sk->protinfo.ax25->digipeat, sizeof(ax25_digi));
+		sk->protinfo.ax25->digipeat = NULL;
+	}
+
 	/*
 	 *	Handle digi-peaters to be used.
 	 */
-	if (addr_len == sizeof(struct full_sockaddr_ax25) && addr->sax25_ndigis != 0) {
-		int ct           = 0;
-		struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)addr;
-
+	if (addr_len == sizeof(struct full_sockaddr_ax25) && fsa->fsa_ax25.sax25_ndigis != 0) {
 		/* Valid number of digipeaters ? */
-		if (addr->sax25_ndigis < 1 || addr->sax25_ndigis > AX25_MAX_DIGIS)
+		if (fsa->fsa_ax25.sax25_ndigis < 1 || fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGIS)
 			return -EINVAL;
 
-		if (sk->ax25->digipeat == NULL) {
-			if ((sk->ax25->digipeat = (ax25_digi *)kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL)
-				return -ENOMEM;
-		}
+		if ((digi = (ax25_digi *)kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL)
+			return -ENOBUFS;
 
-		sk->ax25->digipeat->ndigi = addr->sax25_ndigis;
+		digi->ndigi      = fsa->fsa_ax25.sax25_ndigis;
+		digi->lastrepeat = -1;
 
-		while (ct < addr->sax25_ndigis) {
-			sk->ax25->digipeat->repeated[ct] = 0;
-			sk->ax25->digipeat->calls[ct] = fsa->fsa_digipeater[ct];
+		while (ct < fsa->fsa_ax25.sax25_ndigis) {
+			if ((fsa->fsa_digipeater[ct].ax25_call[6] & AX25_HBIT) && sk->protinfo.ax25->iamdigi) {
+				digi->repeated[ct] = 1;
+				digi->lastrepeat   = ct;
+			} else {
+				digi->repeated[ct] = 0;
+			}
+			digi->calls[ct] = fsa->fsa_digipeater[ct];
 			ct++;
 		}
-
-		sk->ax25->digipeat->lastrepeat = 0;
 	}
 
 	/*
@@ -1425,43 +1445,46 @@
 	 *	been filled in, error if it hasn't.
 	 */
 	if (sk->zapped) {
-		if ((err = ax25_rt_autobind(sk->ax25, &addr->sax25_call)) < 0)
+		if ((err = ax25_rt_autobind(sk->protinfo.ax25, &fsa->fsa_ax25.sax25_call)) < 0)
 			return err;
-		ax25_fillin_cb(sk->ax25, sk->ax25->device);
-		ax25_insert_socket(sk->ax25);
+		ax25_fillin_cb(sk->protinfo.ax25, sk->protinfo.ax25->device);
+		ax25_insert_socket(sk->protinfo.ax25);
 	} else {
-		if (sk->ax25->device == NULL)
+		if (sk->protinfo.ax25->device == NULL)
 			return -EHOSTUNREACH;
 	}
-		
-	if (sk->type == SOCK_SEQPACKET && ax25_find_cb(&sk->ax25->source_addr, &addr->sax25_call, sk->ax25->device) != NULL)
-		return -EBUSY;				/* Already such a connection */
 
-	sk->ax25->dest_addr = addr->sax25_call;
-	
+	if (sk->type == SOCK_SEQPACKET && ax25_find_cb(&sk->protinfo.ax25->source_addr, &fsa->fsa_ax25.sax25_call, digi, sk->protinfo.ax25->device) != NULL) {
+		if (digi != NULL) kfree_s(digi, sizeof(ax25_digi));
+		return -EADDRINUSE;			/* Already such a connection */
+	}
+
+	sk->protinfo.ax25->dest_addr = fsa->fsa_ax25.sax25_call;
+	sk->protinfo.ax25->digipeat  = digi;
+
 	/* First the easy one */
 	if (sk->type != SOCK_SEQPACKET) {
 		sock->state = SS_CONNECTED;
 		sk->state   = TCP_ESTABLISHED;
 		return 0;
 	}
-	
-	/* Move to connecting socket, ax.25 lapb WAIT_UA.. */	
+
+	/* Move to connecting socket, ax.25 lapb WAIT_UA.. */
 	sock->state        = SS_CONNECTING;
 	sk->state          = TCP_SYN_SENT;
-	
-	if (ax25_dev_is_dama_slave(sk->ax25->device))
-		dama_establish_data_link(sk->ax25);
+
+	if (ax25_dev_is_dama_slave(sk->protinfo.ax25->device))
+		dama_establish_data_link(sk->protinfo.ax25);
 	else
-		ax25_establish_data_link(sk->ax25);
-		
-	sk->ax25->state     = AX25_STATE_1;
-	ax25_set_timer(sk->ax25);		/* Start going SABM SABM until a UA or a give up and DM */
-	
+		ax25_establish_data_link(sk->protinfo.ax25);
+
+	sk->protinfo.ax25->state = AX25_STATE_1;
+	ax25_set_timer(sk->protinfo.ax25);		/* Start going SABM SABM until a UA or a give up and DM */
+
 	/* Now the loop */
 	if (sk->state != TCP_ESTABLISHED && (flags & O_NONBLOCK))
 		return -EINPROGRESS;
-		
+
 	cli();	/* To avoid races on the sleep */
 
 	/* A DM or timeout will go to closed, a UA will go to ABM */
@@ -1473,21 +1496,20 @@
 		}
 	}
 
-	if (sk->state != TCP_ESTABLISHED) 
-	{
+	if (sk->state != TCP_ESTABLISHED) {
 		/* Not in ABM, not in WAIT_UA -> failed */
 		sti();
 		sock->state = SS_UNCONNECTED;
 		return sock_error(sk);	/* Always set at this point */
 	}
-	
+
 	sock->state = SS_CONNECTED;
 
 	sti();
-	
+
 	return 0;
 }
-	
+
 static int ax25_socketpair(struct socket *sock1, struct socket *sock2)
 {
 	return -EOPNOTSUPP;
@@ -1499,19 +1521,22 @@
 	struct sock *newsk;
 	struct sk_buff *skb;
 
-	if (newsock->data)
-		sk_free(newsock->data);
+	if (newsock->data != NULL) {
+		sk = (struct sock *)newsock->data;
+		ax25_destroy_socket(sk->protinfo.ax25);
+	}
 
 	newsock->data = NULL;
-	
-	sk = (struct sock *)sock->data;
+
+	if ((sk = (struct sock *)sock->data) == NULL)
+		return -EINVAL;
 
 	if (sk->type != SOCK_SEQPACKET)
 		return -EOPNOTSUPP;
-	
+
 	if (sk->state != TCP_LISTEN)
 		return -EINVAL;
-		
+
 	/*
 	 *	The write queue this time is holding sockets ready to use
 	 *	hooked into the SABM we saved
@@ -1521,7 +1546,7 @@
 		if ((skb = skb_dequeue(&sk->receive_queue)) == NULL) {
 			if (flags & O_NONBLOCK) {
 				sti();
-				return 0;
+				return -EWOULDBLOCK;
 			}
 			interruptible_sleep_on(sk->sleep);
 			if (current->signal & ~current->blocked) {
@@ -1550,49 +1575,49 @@
 	int *uaddr_len, int peer)
 {
 	struct full_sockaddr_ax25 *sax = (struct full_sockaddr_ax25 *)uaddr;
-	struct sock *sk;
+	struct sock *sk = (struct sock *)sock->data;
 	unsigned char ndigi, i;
-	
-	sk = (struct sock *)sock->data;
-	
+
 	if (peer != 0) {
 		if (sk->state != TCP_ESTABLISHED)
 			return -ENOTCONN;
 
 		sax->fsa_ax25.sax25_family = AF_AX25;
-		sax->fsa_ax25.sax25_call   = sk->ax25->dest_addr;
+		sax->fsa_ax25.sax25_call   = sk->protinfo.ax25->dest_addr;
 		sax->fsa_ax25.sax25_ndigis = 0;
 		*uaddr_len = sizeof(struct full_sockaddr_ax25);
 
-		if (sk->ax25->digipeat != NULL) {
-			ndigi = sk->ax25->digipeat->ndigi;
+		if (sk->protinfo.ax25->digipeat != NULL) {
+			ndigi = sk->protinfo.ax25->digipeat->ndigi;
 			sax->fsa_ax25.sax25_ndigis = ndigi;
 			for (i = 0; i < ndigi; i++)
-				sax->fsa_digipeater[i] = sk->ax25->digipeat->calls[i];
+				sax->fsa_digipeater[i] = sk->protinfo.ax25->digipeat->calls[i];
 		}
 	} else {
 		sax->fsa_ax25.sax25_family = AF_AX25;
-		sax->fsa_ax25.sax25_call   = sk->ax25->source_addr;
+		sax->fsa_ax25.sax25_call   = sk->protinfo.ax25->source_addr;
 		sax->fsa_ax25.sax25_ndigis = 1;
 		*uaddr_len = sizeof(struct full_sockaddr_ax25);
 
-		if (sk->ax25->device != NULL)
-			memcpy(&sax->fsa_digipeater[0], sk->ax25->device->dev_addr, AX25_ADDR_LEN);
+		if (sk->protinfo.ax25->device != NULL)
+			memcpy(&sax->fsa_digipeater[0], sk->protinfo.ax25->device->dev_addr, AX25_ADDR_LEN);
 		else
 			sax->fsa_digipeater[0] = null_ax25_address;
 	}
-		
+
 	return 0;
 }
- 
+
 static int ax25_rcv(struct sk_buff *skb, struct device *dev, ax25_address *dev_addr, struct packet_type *ptype)
 {
 	struct sock *make;
 	struct sock *sk;
 	int type = 0;
-	ax25_digi dp;
+	ax25_digi dp, reverse_dp;
+	struct sk_buff *skbn;
 	ax25_cb *ax25;
 	ax25_address src, dest;
+	ax25_address *next_digi = NULL;
 	struct sock *raw;
 	int mine = 0;
 	int dama;
@@ -1600,20 +1625,20 @@
 	/*
 	 *	Process the AX.25/LAPB frame.
 	 */
-	 
+
 	skb->h.raw = skb->data;
-	
+
 #ifdef CONFIG_FIREWALL
 	if (call_in_firewall(PF_AX25, skb->dev, skb->h.raw, NULL) != FW_ACCEPT) {
 		kfree_skb(skb, FREE_READ);
 		return 0;
 	}
-#endif	
+#endif
 
 	/*
 	 *	Parse the address header.
 	 */
-	 
+
 	if (ax25_parse_addr(skb->data, skb->len, &src, &dest, &dp, &type, &dama) == NULL) {
 		kfree_skb(skb, FREE_READ);
 		return 0;
@@ -1622,51 +1647,8 @@
 	/*
 	 *	Ours perhaps ?
 	 */
-	if (dp.lastrepeat + 1 < dp.ndigi) {		/* Not yet digipeated completely */
-		if (ax25cmp(&dp.calls[dp.lastrepeat + 1], dev_addr) == 0) {
-			struct device *dev_out = dev;
-
-			/* We are the digipeater. Mark ourselves as repeated
-			   and throw the packet back out of the same device */
-			dp.lastrepeat++;
-			dp.repeated[(int)dp.lastrepeat] = 1;
-
-			if (ax25_dev_get_value(dev, AX25_VALUES_DIGI) & AX25_DIGI_XBAND) {
-				while (dp.lastrepeat + 1 < dp.ndigi) {
-					struct device *dev_scan;
-					if ((dev_scan = ax25rtr_get_dev(&dp.calls[dp.lastrepeat + 1])) == NULL)
-						break;
-					dp.lastrepeat++;
-					dp.repeated[(int)dp.lastrepeat] = 1;
-					dev_out = dev_scan;
-				}
-				if (dev != dev_out && (ax25_dev_get_value(dev_out, AX25_VALUES_DIGI) & AX25_DIGI_XBAND) == 0) {
-					kfree_skb(skb, FREE_READ);
-					return 0;
-				}
-			}
-
-			if (dev == dev_out && (ax25_dev_get_value(dev, AX25_VALUES_DIGI) & AX25_DIGI_INBAND) == 0) {
-				kfree_skb(skb, FREE_READ);
-				return 0;
-			}
-
-			build_ax25_addr(skb->data, &src, &dest, &dp, type, MODULUS);
-#ifdef CONFIG_FIREWALL
-			if (call_fw_firewall(PF_AX25, skb->dev, skb->data, NULL) != FW_ACCEPT) {
-				kfree_skb(skb, FREE_READ);
-				return 0;
-			}
-#endif
-
-			skb->arp = 1;
-			ax25_queue_xmit(skb, dev_out, SOPRI_NORMAL);
-		} else {
-			kfree_skb(skb, FREE_READ);
-		}
-
-		return 0;
-	}
+	if (dp.lastrepeat + 1 < dp.ndigi)		/* Not yet digipeated completely */
+		next_digi = &dp.calls[dp.lastrepeat + 1];
 
 	/*
 	 *	Pull of the AX.25 headers leaving the CTRL/PID bytes
@@ -1674,16 +1656,15 @@
 	skb_pull(skb, size_ax25_addr(&dp));
 
 	/* For our port addresses ? */
-	if (ax25cmp(&dest, dev_addr) == 0)
+	if (ax25cmp(&dest, dev_addr) == 0 && dp.lastrepeat + 1 == dp.ndigi)
 		mine = 1;
 
-#ifdef CONFIG_NETROM
-	/* Also match on any NET/ROM callsign */
-	if (!mine && nr_dev_get(&dest) != NULL)
+	/* Also match on any registered callsign from L3/4 */
+	if (!mine && ax25_listen_mine(&dest, dev) && dp.lastrepeat + 1 == dp.ndigi)
 		mine = 1;
-#endif	
-	
-	if ((*skb->data & ~0x10) == LAPB_UI) {	/* UI frame - bypass LAPB processing */
+
+	/* UI frame - bypass LAPB processing */
+	if ((*skb->data & ~0x10) == AX25_UI && dp.lastrepeat + 1 == dp.ndigi) {
 		skb->h.raw = skb->data + 2;		/* skip control and pid */
 
 		if ((raw = ax25_addr_match(&dest)) != NULL)
@@ -1696,8 +1677,12 @@
 
 		/* Now we are pointing at the pid byte */
 		switch (skb->data[1]) {
-#ifdef CONFIG_INET		
+#ifdef CONFIG_INET
 			case AX25_P_IP:
+				if ((skbn = skb_copy(skb, GFP_ATOMIC)) != NULL) {
+					kfree_skb(skb, FREE_READ);
+					skb = skbn;
+				}
 				skb_pull(skb,2);		/* drop PID/CTRL */
 				ip_rcv(skb, dev, ptype);	/* Note ptype here is the wrong one, fix me later */
 				break;
@@ -1706,7 +1691,7 @@
 				skb_pull(skb,2);
 				arp_rcv(skb, dev, ptype);	/* Note ptype here is wrong... */
 				break;
-#endif				
+#endif
 			case AX25_P_TEXT:
 				/* Now find a suitable dgram socket */
 				if ((sk = ax25_find_socket(&dest, &src, SOCK_DGRAM)) != NULL) {
@@ -1717,16 +1702,13 @@
 						 *	Remove the control and PID.
 						 */
 						skb_pull(skb, 2);
-						skb_queue_tail(&sk->receive_queue, skb);
-						skb->sk = sk;
-						atomic_add(skb->truesize, &sk->rmem_alloc);
-						if (!sk->dead)
-							sk->data_ready(sk, skb->len);
+						if (sock_queue_rcv_skb(sk, skb) != 0)
+							kfree_skb(skb, FREE_READ);
 					}
 				} else {
 					kfree_skb(skb, FREE_READ);
 				}
-				break;	
+				break;
 
 			default:
 				kfree_skb(skb, FREE_READ);	/* Will scan SOCK_AX25 RAW sockets */
@@ -1741,18 +1723,20 @@
 	 *	If not, should we DM the incoming frame (except DMs) or
 	 *	silently ignore them. For now we stay quiet.
 	 */
-	if (!ax25_dev_get_value(dev, AX25_VALUES_CONMODE)) {
+	if (ax25_dev_get_value(dev, AX25_VALUES_CONMODE) == 0) {
 		kfree_skb(skb, FREE_READ);
 		return 0;
 	}
-	
+
 	/* LAPB */
-	
+
 	/* AX.25 state 1-4 */
-	
-	if ((ax25 = ax25_find_cb(&dest, &src, dev)) != NULL) {
+
+	ax25_digi_invert(&dp, &reverse_dp);
+
+	if ((ax25 = ax25_find_cb(&dest, &src, &reverse_dp, dev)) != NULL) {
 		/*
-		 *	Process the frame. If it is queued up internally it returns one otherwise we 
+		 *	Process the frame. If it is queued up internally it returns one otherwise we
 		 *	free it immediately. This routine itself wakes the user context layers so we
 		 *	do no further work
 		 */
@@ -1765,13 +1749,13 @@
 	/* AX.25 state 0 (disconnected) */
 
 	/* a) received not a SABM(E) */
-	
-	if ((*skb->data & ~PF) != SABM && (*skb->data & ~PF) != SABME) {
+
+	if ((*skb->data & ~AX25_PF) != AX25_SABM && (*skb->data & ~AX25_PF) != AX25_SABME) {
 		/*
 		 *	Never reply to a DM. Also ignore any connects for
 		 *	addresses that are not our interfaces and not a socket.
 		 */
-		if ((*skb->data & ~PF) != DM && mine)
+		if ((*skb->data & ~AX25_PF) != AX25_DM && mine)
 			ax25_return_dm(dev, &src, &dest, &dp);
 
 		kfree_skb(skb, FREE_READ);
@@ -1779,8 +1763,13 @@
 	}
 
 	/* b) received SABM(E) */
-	
-	if ((sk = ax25_find_listener(&dest, dev, SOCK_SEQPACKET)) != NULL) {
+
+	if (dp.lastrepeat + 1 == dp.ndigi)
+		sk = ax25_find_listener(&dest, 0, dev, SOCK_SEQPACKET);
+	else
+		sk = ax25_find_listener(next_digi, 1, dev, SOCK_SEQPACKET);
+
+	if (sk != NULL) {
 		if (sk->ack_backlog == sk->max_ack_backlog || (make = ax25_make_new(sk, dev)) == NULL) {
 			if (mine)
 				ax25_return_dm(dev, &src, &dest, &dp);
@@ -1788,8 +1777,8 @@
 			kfree_skb(skb, FREE_READ);
 			return 0;
 		}
-		
-		ax25 = make->ax25;
+
+		ax25 = make->protinfo.ax25;
 
 		skb_queue_head(&sk->receive_queue, skb);
 
@@ -1799,12 +1788,11 @@
 
 		sk->ack_backlog++;
 	} else {
-#ifdef CONFIG_NETROM
 		if (!mine) {
 			kfree_skb(skb, FREE_READ);
 			return 0;
 		}
-		
+
 		if ((ax25 = ax25_create_cb()) == NULL) {
 			ax25_return_dm(dev, &src, &dest, &dp);
 			kfree_skb(skb, FREE_READ);
@@ -1812,14 +1800,6 @@
 		}
 
 		ax25_fillin_cb(ax25, dev);
-		ax25->idletimer = ax25->idle;
-#else
-		if (mine)
-			ax25_return_dm(dev, &src, &dest, &dp);
-
-		kfree_skb(skb, FREE_READ);
-		return 0;
-#endif
 	}
 
 	ax25->source_addr = dest;
@@ -1841,25 +1821,27 @@
 		}
 	} else {
 		/* Reverse the source SABM's path */
-		ax25_digi_invert(&dp, ax25->digipeat);
+		*ax25->digipeat = reverse_dp;
 	}
 
-	if ((*skb->data & ~PF) == SABME) {
-		ax25->modulus = EMODULUS;
+	if ((*skb->data & ~AX25_PF) == AX25_SABME) {
+		ax25->modulus = AX25_EMODULUS;
 		ax25->window  = ax25_dev_get_value(dev, AX25_VALUES_EWINDOW);
 	} else {
-		ax25->modulus = MODULUS;
+		ax25->modulus = AX25_MODULUS;
 		ax25->window  = ax25_dev_get_value(dev, AX25_VALUES_WINDOW);
 	}
 
 	ax25->device = dev;
-	
-	ax25_send_control(ax25, UA, POLLON, C_RESPONSE);
+
+	ax25_send_control(ax25, AX25_UA, AX25_POLLON, AX25_RESPONSE);
 
 	if (dama) ax25_dama_on(ax25);	/* bke 951121 */
 
 	ax25->dama_slave = dama;
-	ax25->t3timer = ax25->t3;
+	ax25->t3timer    = ax25->t3;
+	ax25->idletimer  = ax25->idle;
+
 	ax25->state   = AX25_STATE_3;
 
 	ax25_insert_socket(ax25);
@@ -1893,30 +1875,6 @@
 	return ax25_rcv(skb, dev, (ax25_address *)dev->dev_addr, ptype);
 }
 
-#ifdef CONFIG_BPQETHER
-/*
- *	Receive an AX.25 frame via an Ethernet interface.
- */
-static int bpq_rcv(struct sk_buff *skb, struct device *dev, struct packet_type *ptype)
-{
-	ax25_address *port_call;
-	int len;
-
-	skb->sk = NULL;		/* Initially we don't know who it's for */
-
-	if ((port_call = ax25_bpq_get_addr(dev)) == NULL) {
-		kfree_skb(skb, FREE_READ);	/* We have no port callsign */
-		return 0;
-	}
-
-	len = skb->data[0] + skb->data[1] * 256 - 5;
-
-	skb_pull(skb, 2);	/* Remove the length bytes */
-	skb_trim(skb, len);	/* Set the length of the data */
-
-	return ax25_rcv(skb, dev, port_call, ptype);
-}
-#endif
 
 static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len, int noblock, int flags)
 {
@@ -1931,7 +1889,7 @@
 	ax25_digi dtmp;
 	int lv;
 	int addr_len = msg->msg_namelen;
-	
+
 	if (sk->err)
 		return sock_error(sk);
 
@@ -1940,11 +1898,16 @@
 
 	if (sk->zapped)
 		return -EADDRNOTAVAIL;
-		
-	if (sk->ax25->device == NULL)
+
+	if (sk->shutdown & SEND_SHUTDOWN) {
+		send_sig(SIGPIPE, current, 0);
+		return -EPIPE;
+	}
+
+	if (sk->protinfo.ax25->device == NULL)
 		return -ENETUNREACH;
-		
-	if (usax) {
+
+	if (usax != NULL) {
 		if (addr_len != sizeof(struct sockaddr_ax25) && addr_len != sizeof(struct full_sockaddr_ax25))
 			return -EINVAL;
 		if (usax->sax25_family != AF_AX25)
@@ -1969,7 +1932,7 @@
 		}
 
 		sax = *usax;
-		if (sk->type == SOCK_SEQPACKET && ax25cmp(&sk->ax25->dest_addr, &sax.sax25_call) != 0)
+		if (sk->type == SOCK_SEQPACKET && ax25cmp(&sk->protinfo.ax25->dest_addr, &sax.sax25_call) != 0)
 			return -EISCONN;
 		if (usax->sax25_ndigis == 0)
 			dp = NULL;
@@ -1979,10 +1942,10 @@
 		if (sk->state != TCP_ESTABLISHED)
 			return -ENOTCONN;
 		sax.sax25_family = AF_AX25;
-		sax.sax25_call   = sk->ax25->dest_addr;
-		dp = sk->ax25->digipeat;
+		sax.sax25_call   = sk->protinfo.ax25->dest_addr;
+		dp = sk->protinfo.ax25->digipeat;
 	}
-	
+
 	if (sk->debug)
 		printk("AX.25: sendto: Addresses built.\n");
 
@@ -1998,7 +1961,6 @@
 
 	skb->sk   = sk;
 	skb->free = 1;
-	skb->arp  = 1;
 
 	skb_reserve(skb, size - len);
 
@@ -2008,9 +1970,11 @@
 	/* User data follows immediately after the AX.25 data */
 	memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
 
-	/* Add the PID, usually AX25_TEXT */
-	asmptr  = skb_push(skb, 1);
-	*asmptr = sk->protocol;
+	/* Add the PID if one is not supplied by the user in the skb */
+	if (!sk->protinfo.ax25->pidincl) {
+		asmptr  = skb_push(skb, 1);
+		*asmptr = sk->protocol;
+	}
 
 	if (sk->debug)
 		printk("AX.25: Transmitting buffer\n");
@@ -2022,7 +1986,7 @@
 			return -ENOTCONN;
 		}
 
-		ax25_output(sk->ax25, skb);	/* Shove it onto the queue and kick */
+		ax25_output(sk->protinfo.ax25, sk->protinfo.ax25->paclen, skb);	/* Shove it onto the queue and kick */
 
 		return len;
 	} else {
@@ -2035,38 +1999,36 @@
 		}
 
 		/* Build an AX.25 header */
-		asmptr += (lv = build_ax25_addr(asmptr, &sk->ax25->source_addr, &sax.sax25_call, dp, C_COMMAND, MODULUS));
+		asmptr += (lv = build_ax25_addr(asmptr, &sk->protinfo.ax25->source_addr, &sax.sax25_call, dp, AX25_COMMAND, AX25_MODULUS));
 
 		if (sk->debug)
 			printk("Built header (%d bytes)\n",lv);
 
 		skb->h.raw = asmptr;
-	
+
 		if (sk->debug)
 			printk("base=%p pos=%p\n", skb->data, asmptr);
 
-		*asmptr = LAPB_UI;
+		*asmptr = AX25_UI;
 
 		/* Datagram frames go straight out of the door as UI */
-		ax25_queue_xmit(skb, sk->ax25->device, SOPRI_NORMAL);
+		ax25_queue_xmit(skb, sk->protinfo.ax25->device, SOPRI_NORMAL);
 
 		return len;
 	}
-		
 }
 
 static int ax25_recvmsg(struct socket *sock, struct msghdr *msg, int size, int noblock, int flags, int *addr_len)
 {
 	struct sock *sk = (struct sock *)sock->data;
 	struct sockaddr_ax25 *sax = (struct sockaddr_ax25 *)msg->msg_name;
-	int copied, length;
+	int copied;
 	struct sk_buff *skb;
 	int er;
-	int dama;
 
 	if (sk->err)
 		return sock_error(sk);
-	
+
 	if (addr_len != NULL)
 		*addr_len = sizeof(*sax);
 
@@ -2081,23 +2043,20 @@
 	if ((skb = skb_recv_datagram(sk, flags, noblock, &er)) == NULL)
 		return er;
 
-	if (sk->ax25->hdrincl) {
-		length = skb->len + (skb->data - skb->h.raw);
-	} else {
-		if (sk->type == SOCK_SEQPACKET)
-			skb_pull(skb, 1);		/* Remove PID */
-		length     = skb->len;
-		skb->h.raw = skb->data;
-	}
+	if (!sk->protinfo.ax25->pidincl)
+		skb_pull(skb, 1);		/* Remove PID */
 
-	copied = (size < length) ? size : length;
+	skb->h.raw = skb->data;
+
+	copied = (size < skb->len) ? size : skb->len;
 	skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
 	
-	if (sax) {
+	if (sax != NULL) {
 		ax25_digi digi;
 		ax25_address dest;
+		int dama;
 
-		if (addr_len == (int *)0)
+		if (addr_len == NULL)
 			return -EINVAL;
 		if (*addr_len != sizeof(struct sockaddr_ax25) && *addr_len != sizeof(struct full_sockaddr_ax25))
 			return -EINVAL;
@@ -2129,7 +2088,7 @@
 	skb_free_datagram(sk, skb);
 
 	return copied;
-}		
+}
 
 static int ax25_shutdown(struct socket *sk, int how)
 {
@@ -2148,34 +2107,36 @@
 {
 	struct sock *sk = (struct sock *)sock->data;
 	int err;
-	long amount = 0;
 
 	switch (cmd) {
-		case TIOCOUTQ:
-			if ((err = verify_area(VERIFY_WRITE, (void *)arg, sizeof(unsigned long))) != 0)
+		case TIOCOUTQ: {
+			long amount;
+			if ((err = verify_area(VERIFY_WRITE, (void *)arg, sizeof(int))) != 0)
 				return err;
 			amount = sk->sndbuf - sk->wmem_alloc;
 			if (amount < 0)
 				amount = 0;
-			put_fs_long(amount, (unsigned long *)arg);
+			put_fs_long(amount, (int *)arg);
 			return 0;
+		}
 
 		case TIOCINQ: {
 			struct sk_buff *skb;
+			long amount = 0L;
 			/* These two are safe on a single CPU system as only user tasks fiddle here */
 			if ((skb = skb_peek(&sk->receive_queue)) != NULL)
 				amount = skb->len;
-			if ((err = verify_area(VERIFY_WRITE, (void *)arg, sizeof(unsigned long))) != 0)
+			if ((err = verify_area(VERIFY_WRITE, (void *)arg, sizeof(int))) != 0)
 				return err;
-			put_fs_long(amount, (unsigned long *)arg);
+			put_fs_long(amount, (int *)arg);
 			return 0;
 		}
 
 		case SIOCGSTAMP:
 			if (sk != NULL) {
-				if (sk->stamp.tv_sec==0)
+				if (sk->stamp.tv_sec == 0)
 					return -ENOENT;
-				if ((err = verify_area(VERIFY_WRITE,(void *)arg,sizeof(struct timeval))) != 0)
+				if ((err = verify_area(VERIFY_WRITE, (void *)arg, sizeof(struct timeval))) != 0)
 					return err;
 				memcpy_tofs((void *)arg, &sk->stamp, sizeof(struct timeval));
 				return 0;
@@ -2192,27 +2153,18 @@
 			return ax25_uid_ioctl(cmd, &sax25);
 		}
 
-		case SIOCAX25NOUID:	/* Set the default policy (default/bar) */
+		case SIOCAX25NOUID: {	/* Set the default policy (default/bar) */
+			long amount;
 			if ((err = verify_area(VERIFY_READ, (void *)arg, sizeof(unsigned long))) != 0)
 				return err;
-			if(!suser())
+			if (!suser())
 				return -EPERM;
 			amount = get_fs_long((void *)arg);
 			if (amount > AX25_NOUID_BLOCK)
 				return -EINVAL;
 			ax25_uid_policy = amount;
 			return 0;
-
-#ifdef CONFIG_BPQETHER
-		case SIOCAX25BPQADDR:
-			if (!suser())
-				return -EPERM;
-			return ax25_bpq_ioctl(cmd, (void *)arg);
-#endif
-
-		case SIOCAX25GETPARMS:
-		case SIOCAX25SETPARMS:
-			return ax25_dev_ioctl(cmd, (void *)arg);
+		}
 
 		case SIOCADDRT:
 		case SIOCDELRT:
@@ -2220,12 +2172,44 @@
 			if (!suser())
 				return -EPERM;
 			return ax25_rt_ioctl(cmd, (void *)arg);
-			
+
 		case SIOCAX25CTLCON:
 			if (!suser())
 				return -EPERM;
 			return ax25_ctl_ioctl(cmd, (void *)arg);
 
+		case SIOCAX25GETINFO: {
+			struct ax25_info_struct ax25_info;
+			if ((err = verify_area(VERIFY_WRITE, (void *)arg, sizeof(ax25_info))) != 0)
+				return err;
+			ax25_info.t1        = sk->protinfo.ax25->t1   / AX25_SLOWHZ;
+			ax25_info.t2        = sk->protinfo.ax25->t2   / AX25_SLOWHZ;
+			ax25_info.t3        = sk->protinfo.ax25->t3   / AX25_SLOWHZ;
+			ax25_info.idle      = sk->protinfo.ax25->idle / (60 * AX25_SLOWHZ);
+			ax25_info.n2        = sk->protinfo.ax25->n2;
+			ax25_info.t1timer   = sk->protinfo.ax25->t1timer   / AX25_SLOWHZ;
+			ax25_info.t2timer   = sk->protinfo.ax25->t2timer   / AX25_SLOWHZ;
+			ax25_info.t3timer   = sk->protinfo.ax25->t3timer   / AX25_SLOWHZ;
+			ax25_info.idletimer = sk->protinfo.ax25->idletimer / (60 * AX25_SLOWHZ);
+			ax25_info.n2count   = sk->protinfo.ax25->n2count;
+			ax25_info.state     = sk->protinfo.ax25->state;
+			ax25_info.rcv_q     = sk->rmem_alloc;
+			ax25_info.snd_q     = sk->wmem_alloc;
+			memcpy_tofs((void *)arg, &ax25_info, sizeof(ax25_info));
+			return 0;
+		}
+
+		case SIOCAX25ADDFWD:
+		case SIOCAX25DELFWD: {
+			struct ax25_fwd_struct ax25_fwd;
+			if (!suser())
+				return -EPERM;
+			if ((err = verify_area(VERIFY_READ, (void *)arg, sizeof(ax25_fwd))) != 0)
+				return err;
+			memcpy_fromfs(&ax25_fwd, (void *)arg, sizeof(ax25_fwd));
+			return ax25_fwd_ioctl(cmd, &ax25_fwd);
+		}
+
 		case SIOCGIFADDR:
 		case SIOCSIFADDR:
 		case SIOCGIFDSTADDR:
@@ -2252,13 +2236,14 @@
 	ax25_cb *ax25;
 	struct device *dev;
 	const char *devname;
+	char callbuf[15];
 	int len = 0;
 	off_t pos = 0;
 	off_t begin = 0;
 
 	cli();
 
-	len += sprintf(buffer, "dest_addr src_addr  dev  st  vs  vr  va    t1     t2     t3      idle   n2  rtt wnd paclen   dama Snd-Q Rcv-Q\n");
+	len += sprintf(buffer, "dest_addr src_addr   dev  st  vs  vr  va    t1     t2     t3      idle   n2  rtt wnd paclen Snd-Q Rcv-Q Inode\n");
 
 	for (ax25 = ax25_list; ax25 != NULL; ax25 = ax25->next) {
 		if ((dev = ax25->device) == NULL)
@@ -2268,40 +2253,46 @@
 
 		len += sprintf(buffer + len, "%-9s ",
 			ax2asc(&ax25->dest_addr));
-		len += sprintf(buffer + len, "%-9s %-4s %2d %3d %3d %3d %3d/%03d %2d/%02d %3d/%03d %3d/%03d %2d/%02d %3d %3d  %5d",
-			ax2asc(&ax25->source_addr), devname,
+
+		sprintf(callbuf, "%s%c", ax2asc(&ax25->source_addr),
+					 (ax25->iamdigi) ? '*' : ' ');
+
+		len += sprintf(buffer + len, "%-10s %-4s %2d %3d %3d %3d %3d/%03d %2d/%02d %3d/%03d %3d/%03d %2d/%02d %3d %3d  %5d",
+			callbuf, devname,
 			ax25->state,
 			ax25->vs, ax25->vr, ax25->va,
-			ax25->t1timer / PR_SLOWHZ,
-			ax25->t1      / PR_SLOWHZ,
-			ax25->t2timer / PR_SLOWHZ,
-			ax25->t2      / PR_SLOWHZ,
-			ax25->t3timer / PR_SLOWHZ,
-			ax25->t3      / PR_SLOWHZ,
-			ax25->idletimer / (PR_SLOWHZ * 60),
-			ax25->idle      / (PR_SLOWHZ * 60),
+			ax25->t1timer / AX25_SLOWHZ,
+			ax25->t1      / AX25_SLOWHZ,
+			ax25->t2timer / AX25_SLOWHZ,
+			ax25->t2      / AX25_SLOWHZ,
+			ax25->t3timer / AX25_SLOWHZ,
+			ax25->t3      / AX25_SLOWHZ,
+			ax25->idletimer / (AX25_SLOWHZ * 60),
+			ax25->idle      / (AX25_SLOWHZ * 60),
 			ax25->n2count, ax25->n2,
-			ax25->rtt     / PR_SLOWHZ,
+			ax25->rtt     / AX25_SLOWHZ,
 			ax25->window,
 			ax25->paclen);
-			
-		len += sprintf(buffer + len, " %s", ax25->dama_slave ? " slave" : "    no");
 
 		if (ax25->sk != NULL) {
-			len += sprintf(buffer + len, " %5d %5d\n",
-				ax25->sk->wmem_alloc,
-				ax25->sk->rmem_alloc);
+			struct sock *s = ax25->sk;
+
+			len += sprintf(buffer + len, " %5d %5d %ld\n",
+				s->wmem_alloc,
+				s->rmem_alloc,
+				s->socket && SOCK_INODE(s->socket) ?
+				SOCK_INODE(s->socket)->i_ino : 0);
 		} else {
 			len += sprintf(buffer + len, "\n");
 		}
-		
+
 		pos = begin + len;
 
 		if (pos < offset) {
 			len   = 0;
 			begin = pos;
 		}
-		
+
 		if (pos > offset + length)
 			break;
 	}
@@ -2318,7 +2309,7 @@
 
 static struct proto_ops ax25_proto_ops = {
 	AF_AX25,
-	
+
 	ax25_create,
 	ax25_dup,
 	ax25_release,
@@ -2341,8 +2332,7 @@
 /*
  *	Called by socket.c on kernel start up
  */
-
-static struct packet_type ax25_packet_type = 
+static struct packet_type ax25_packet_type =
 {
 	0,	/* MUTTER ntohs(ETH_P_AX25),*/
 	0,		/* copy */
@@ -2351,111 +2341,94 @@
 	NULL,
 };
 
-#ifdef CONFIG_BPQETHER
-static struct packet_type bpq_packet_type = 
-{
-	0,	/* MUTTER ntohs(ETH_P_BPQ),*/
-	0,		/* copy */
-	bpq_rcv,
-	NULL,
-	NULL,
-};
-#endif
-
 static struct notifier_block ax25_dev_notifier = {
 	ax25_device_event,
 	0
 };
 
+#ifdef CONFIG_PROC_FS
+static struct proc_dir_entry proc_ax25_route = {
+	PROC_NET_AX25_ROUTE, 10, "ax25_route",
+	S_IFREG | S_IRUGO, 1, 0, 0,
+	0, &proc_net_inode_operations,
+	ax25_rt_get_info
+};
+static struct proc_dir_entry proc_ax25 = {
+	PROC_NET_AX25, 4, "ax25",
+	S_IFREG | S_IRUGO, 1, 0, 0,
+	0, &proc_net_inode_operations,
+	ax25_get_info
+};
+static struct proc_dir_entry proc_ax25_calls = {
+	PROC_NET_AX25_CALLS, 10, "ax25_calls",
+	S_IFREG | S_IRUGO, 1, 0, 0,
+	0, &proc_net_inode_operations,
+	ax25_cs_get_info
+};
+#endif
+
+static struct symbol_table ax25_syms = {
+#include <linux/symtab_begin.h>
+	X(ax25_encapsulate),
+	X(ax25_rebuild_header),
+	X(ax25_findbyuid),
+	X(ax25_find_cb),
+	X(ax25_linkfail_register),
+	X(ax25_linkfail_release),
+	X(ax25_listen_register),
+	X(ax25_listen_release),
+	X(ax25_protocol_register),
+	X(ax25_protocol_release),
+	X(ax25_send_frame),
+	X(ax25_uid_policy),
+	X(ax25cmp),
+	X(ax2asc),
+	X(asc2ax),
+	X(null_ax25_address),
+#include <linux/symtab_end.h>
+};
+
 void ax25_proto_init(struct net_proto *pro)
 {
 	sock_register(ax25_proto_ops.family, &ax25_proto_ops);
 	ax25_packet_type.type = htons(ETH_P_AX25);
-	dev_add_pack(&ax25_packet_type);	
-#ifdef CONFIG_BPQETHER
-	bpq_packet_type.type  = htons(ETH_P_BPQ);
-	dev_add_pack(&bpq_packet_type);
-#endif
+	dev_add_pack(&ax25_packet_type);
 	register_netdevice_notifier(&ax25_dev_notifier);
-#ifdef CONFIG_PROC_FS			  
-	proc_net_register(&(struct proc_dir_entry) {
-		PROC_NET_AX25_ROUTE, 10, "ax25_route",
-		S_IFREG | S_IRUGO, 1, 0, 0,
-		0, &proc_net_inode_operations,
-		ax25_rt_get_info
-	});
-	proc_net_register(&(struct proc_dir_entry) {
-		PROC_NET_AX25, 4, "ax25",
-		S_IFREG | S_IRUGO, 1, 0, 0,
-		0, &proc_net_inode_operations,
-		ax25_get_info
-	});
-	proc_net_register(&(struct proc_dir_entry) {
-		PROC_NET_AX25_CALLS, 10, "ax25_calls",
-		S_IFREG | S_IRUGO, 1, 0, 0,
-		0, &proc_net_inode_operations,
-		ax25_cs_get_info
-	});
-#endif	
-
-	printk(KERN_INFO "G4KLX/GW4PTS AX.25 for Linux. Version 0.32 for Linux NET3.035 (Linux 2.0)\n");
-
-#ifdef CONFIG_BPQETHER
-	proc_net_register(&(struct proc_dir_entry) {
-		PROC_NET_AX25_BPQETHER, 13, "ax25_bpqether",
-		S_IFREG | S_IRUGO, 1, 0, 0,
-		0, &proc_net_inode_operations,
-		ax25_bpq_get_info
-	});
+	ax25_register_sysctl();
+	register_symtab(&ax25_syms);
 
-	printk(KERN_INFO "G8BPQ Encapsulation of AX.25 frames enabled\n");
+#ifdef CONFIG_PROC_FS
+	proc_net_register(&proc_ax25_route);
+	proc_net_register(&proc_ax25);
+	proc_net_register(&proc_ax25_calls);
 #endif
+
+	printk(KERN_INFO "G4KLX/GW4PTS AX.25 for Linux. Version 0.35 for Linux NET3.035 (Linux 2.0)\n");
 }
 
 /*
- *	A small shim to dev_queue_xmit to handle the difference between
- *	KISS AX.25 and BPQ AX.25.
+ *	A small shim to dev_queue_xmit to add the KISS control byte, and do
+ *	any packet forwarding in operation.
  */
 void ax25_queue_xmit(struct sk_buff *skb, struct device *dev, int pri)
 {
 	unsigned char *ptr;
-	
+
 #ifdef CONFIG_FIREWALL
 	if (call_out_firewall(PF_AX25, skb->dev, skb->data, NULL) != FW_ACCEPT) {
 		dev_kfree_skb(skb, FREE_WRITE);
 		return;
 	}
-#endif	
-
-	skb->protocol = htons (ETH_P_AX25);
-
-#ifdef CONFIG_BPQETHER
-	if (dev->type == ARPHRD_ETHER) {
-		static char bcast_addr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
-		int size;
-
-		if(skb_headroom(skb) < AX25_BPQ_HEADER_LEN) {
-			printk(KERN_CRIT "ax25_queue_xmit: not enough space to add BPQ Ether header\n");
-			dev_kfree_skb(skb, FREE_WRITE);
-			return;
-		}
-
-		size = skb->len;
-	
-		ptr = skb_push(skb, 2);
+#endif
 
-		*ptr++ = (size + 5) % 256;
-		*ptr++ = (size + 5) / 256;
+	skb->protocol = htons(ETH_P_AX25);
+	skb->dev      = ax25_fwd_dev(dev);
+	skb->arp      = 1;
 
-		dev->hard_header(skb, dev, ETH_P_BPQ, bcast_addr, NULL, 0);
-		dev_queue_xmit(skb, dev, pri);
-		return;
-	} 
-#endif
+	ptr  = skb_push(skb, 1);
+	*ptr = 0x00;			/* KISS */
 
-	ptr = skb_push(skb, 1);
-	*ptr++ = 0;			/* KISS */
-	dev_queue_xmit(skb, dev, pri);
+	dev_queue_xmit(skb, skb->dev, pri);
 }
 
 /*
@@ -2467,7 +2440,7 @@
  */
 
 #ifdef CONFIG_INET
- 
+
 int ax25_encapsulate(struct sk_buff *skb, struct device *dev, unsigned short type, void *daddr,
 		void *saddr, unsigned len)
 {
@@ -2475,13 +2448,13 @@
  	unsigned char *buff = skb_push(skb, AX25_HEADER_LEN);
 
   	*buff++ = 0;	/* KISS DATA */
-  	
+
 	if (daddr != NULL)
 		memcpy(buff, daddr, dev->addr_len);	/* Address specified */
 
-  	buff[6] &= ~LAPB_C;
-  	buff[6] &= ~LAPB_E;
-  	buff[6] |= SSSID_SPARE;
+  	buff[6] &= ~AX25_CBIT;
+  	buff[6] &= ~AX25_EBIT;
+  	buff[6] |= AX25_SSSID_SPARE;
   	buff += AX25_ADDR_LEN;
 
   	if (saddr != NULL)
@@ -2489,49 +2462,54 @@
   	else
   		memcpy(buff, dev->dev_addr, dev->addr_len);
 
-  	buff[6] &= ~LAPB_C;
-  	buff[6] |= LAPB_E;
-  	buff[6] |= SSSID_SPARE;
+  	buff[6] &= ~AX25_CBIT;
+  	buff[6] |= AX25_EBIT;
+  	buff[6] |= AX25_SSSID_SPARE;
   	buff   += AX25_ADDR_LEN;
 
-  	*buff++ = LAPB_UI;	/* UI */
+  	*buff++ = AX25_UI;	/* UI */
 
   	/* Append a suitable AX.25 PID */
   	switch (type) {
   		case ETH_P_IP:
   			*buff++ = AX25_P_IP;
  			break;
-
   		case ETH_P_ARP:
   			*buff++ = AX25_P_ARP;
   			break;
   		default:
-  			printk(KERN_ERR "wrong protocol type 0x%x2.2\n", type);
+  			printk(KERN_ERR "AX.25 wrong protocol type 0x%x2.2\n", type);
   			*buff++ = 0;
   			break;
  	}
-	
+
 	if (daddr != NULL)
 	  	return AX25_HEADER_LEN;
 
 	return -AX25_HEADER_LEN;	/* Unfinished header */
 }
 
-int ax25_rebuild_header(unsigned char *bp, struct device *dev, unsigned long dest, struct sk_buff *skb)
+int ax25_rebuild_header(void *buf, struct device *dev, unsigned long dest, struct sk_buff *skb)
 {
 	struct sk_buff *ourskb;
+	unsigned char *bp = (unsigned char *)buf;
+	ax25_address *src, *dst;
+	ax25_digi *digi;
 	int mode;
 
+	dst = (ax25_address *)(bp + 1);
+	src = (ax25_address *)(bp + 8);
+
   	if (arp_find(bp + 1, dest, dev, dev->pa_addr, skb))
   		return 1;
 
+	digi = ax25_rt_find_path(dst, dev);
+
 	if (bp[16] == AX25_P_IP) {
-		mode = ax25_ip_mode_get((ax25_address *)(bp + 1), dev);
-		if (mode == 'V' || (mode == ' ' && ax25_dev_get_value(dev, AX25_VALUES_IPDEFMODE) == 'V')) {
+		mode = ax25_rt_mode_get(dst, dev);
+
+		if (mode == 'V' || (mode == ' ' && ax25_dev_get_value(dev, AX25_VALUES_IPDEFMODE))) {
 			/*
-			 *	This is a workaround to try to keep the device locking
-			 *	straight until skb->free=0 is abolished post 1.4.
-			 *
 			 *	We clone the buffer and release the original thereby
 			 *	keeping it straight
 			 *
@@ -2541,7 +2519,7 @@
 			 *	as we have pulled the frame from the queue by
 			 *	freeing it).
 			 */
-			if ((ourskb = skb_clone(skb, GFP_ATOMIC)) == NULL) {
+			if ((ourskb = skb_copy(skb, GFP_ATOMIC)) == NULL) {
 				dev_kfree_skb(skb, FREE_WRITE);
 				return 1;
 			}
@@ -2555,30 +2533,59 @@
 
 			skb_pull(ourskb, AX25_HEADER_LEN - 1);	/* Keep PID */
 
-			ax25_send_frame(ourskb, (ax25_address *)(bp + 8), (ax25_address *)(bp + 1), NULL, dev);
+			ax25_send_frame(ourskb, ax25_dev_get_value(dev, AX25_VALUES_PACLEN), src, dst, digi, dev);
 
 			return 1;
 		}
 	}
 
-  	bp[7]  &= ~LAPB_C;
-  	bp[7]  &= ~LAPB_E;
-  	bp[7]  |= SSSID_SPARE;
-
-  	bp[14] &= ~LAPB_C;
-  	bp[14] |= LAPB_E;
-  	bp[14] |= SSSID_SPARE;
-  	
-  	/*
-  	 * dl1bke 960317: we use ax25_queue_xmit here to allow mode datagram
-  	 *		  over ethernet. I don't know if this is valid, though.
-  	 */
-	ax25_dg_build_path(skb, (ax25_address *)(bp + 1), dev);
+  	bp[7]  &= ~AX25_CBIT;
+  	bp[7]  &= ~AX25_EBIT;
+  	bp[7]  |= AX25_SSSID_SPARE;
+
+  	bp[14] &= ~AX25_CBIT;
+  	bp[14] |= AX25_EBIT;
+  	bp[14] |= AX25_SSSID_SPARE;
+
+	skb_pull(skb, AX25_KISS_HEADER_LEN);
+
+	if (digi != NULL)
+		ax25_rt_build_path(skb, src, dst, digi);
+
 	ax25_queue_xmit(skb, dev, SOPRI_NORMAL);
 
   	return 1;
-}	
+}
+
+#endif
 
+#ifdef MODULE
+int init_module(void)
+{
+	ax25_proto_init(NULL);
+
+	return 0;
+}
+
+void cleanup_module(void)
+{
+#ifdef CONFIG_PROC_FS
+	proc_net_unregister(PROC_NET_AX25_ROUTE);
+	proc_net_unregister(PROC_NET_AX25);
+	proc_net_unregister(PROC_NET_AX25_CALLS);
+	proc_net_unregister(PROC_NET_AX25_ROUTE);
+#endif
+	ax25_rt_free();
+
+	ax25_unregister_sysctl();
+
+	unregister_netdevice_notifier(&ax25_dev_notifier);
+
+	ax25_packet_type.type = htons(ETH_P_AX25);
+	dev_remove_pack(&ax25_packet_type);
+
+	sock_unregister(AF_AX25);
+}
 #endif
 
 #endif

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