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

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

diff -u --recursive --new-file v2.0.34/linux/net/ax25/ax25_out.c linux/net/ax25/ax25_out.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
  *
@@ -32,7 +29,7 @@
  */
 
 #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>
@@ -55,48 +52,37 @@
 #include <linux/interrupt.h>
 
 /*
- * All outgoing AX.25 I frames pass via this routine. Therefore this is
- * where the fragmentation of frames takes place.
+ *	All outgoing AX.25 I frames pass via this routine. Therefore this is
+ *	where the fragmentation of frames takes place. If fragment is set to
+ *	zero then we are not allowed to do fragmentation, even if the frame
+ *	is too large.
  */
-void ax25_output(ax25_cb *ax25, struct sk_buff *skb)
+void ax25_output(ax25_cb *ax25, int paclen, struct sk_buff *skb)
 {
 	struct sk_buff *skbn;
 	unsigned char *p;
-	int frontlen, mtu, len, fragno, ka9qfrag, first = 1;
+	int frontlen, len, fragno, ka9qfrag, first = 1;
 	long flags;
-	
-	/*
-	 * dl1bke 960301: We use the new PACLEN parameter as MTU of the AX.25 layer.
-	 *                This will (hopefully) allow user programs to write() data
-	 *                w/o having to think of the maximal amount of data we can
-	 *		  send with one call. It's called PACLEN to (1) avoid confusion
-	 *		  with (IP) MTU and (2) TAPR calls this PACLEN, too ;-)
-	 */
-
-	mtu = ax25->paclen;
-	
-	if ((skb->len - 1) > mtu) {
+
+	if ((skb->len - 1) > paclen) {
 		if (*skb->data == AX25_P_TEXT) {
 			skb_pull(skb, 1); /* skip PID */
 			ka9qfrag = 0;
 		} else {
-			mtu -= 2;	/* Allow for fragment control info */
+			paclen -= 2;	/* Allow for fragment control info */
 			ka9qfrag = 1;
 		}
-		
-		fragno = skb->len / mtu;
-		if (skb->len % mtu == 0) fragno--;
+
+		fragno = skb->len / paclen;
+		if (skb->len % paclen == 0) fragno--;
 
 		frontlen = skb_headroom(skb);	/* Address space + CTRL */
 
 		while (skb->len > 0) {
 			save_flags(flags); 
 			cli();
-			/* 
-			 * do _not_ use sock_alloc_send_skb, our socket may have
-			 * sk->shutdown set...
-			 */
-			if ((skbn = alloc_skb(mtu + 2 + frontlen, GFP_ATOMIC)) == NULL) {
+
+			if ((skbn = alloc_skb(paclen + 2 + frontlen, GFP_ATOMIC)) == NULL) {
 				restore_flags(flags);
 				printk(KERN_DEBUG "ax25_output: alloc_skb returned NULL\n");
 				if (skb_device_locked(skb))
@@ -105,17 +91,15 @@
 			}
 
 			skbn->sk   = skb->sk;
-			
-			if (skbn->sk)
+			skbn->free = 1;
+
+			if (skbn->sk != NULL)
 				atomic_add(skbn->truesize, &skbn->sk->wmem_alloc);
-			
+
 			restore_flags(flags);
-			
-			skbn->free = 1;
-			skbn->arp  = 1;
 
-			len = (mtu > skb->len) ? skb->len : mtu;
-			
+			len = (paclen > skb->len) ? skb->len : paclen;
+
 			if (ka9qfrag == 1) {
 				skb_reserve(skbn, frontlen + 2);
 
@@ -126,7 +110,7 @@
 
 				*p = fragno--;
 				if (first) {
-					*p |= SEG_FIRST;
+					*p |= AX25_SEG_FIRST;
 					first = 0;
 				}
 			} else {
@@ -139,8 +123,7 @@
 			skb_pull(skb, len);
 			skb_queue_tail(&ax25->write_queue, skbn); /* Throw it on the queue */
 		}
-		
-		skb->free = 1;
+
 		kfree_skb(skb, FREE_WRITE);
 	} else {
 		skb_queue_tail(&ax25->write_queue, skb);	  /* Throw it on the queue */
@@ -163,23 +146,25 @@
 	if (skb == NULL)
 		return;
 
-	if (ax25->modulus == MODULUS) {
+	if (ax25->modulus == AX25_MODULUS) {
 		frame = skb_push(skb, 1);
 
-		*frame = I;
-		*frame |= (poll_bit) ? PF : 0;
+		*frame = AX25_I;
+		*frame |= (poll_bit) ? AX25_PF : 0;
 		*frame |= (ax25->vr << 5);
 		*frame |= (ax25->vs << 1);
 	} else {
 		frame = skb_push(skb, 2);
 
-		frame[0] = I;
+		frame[0] = AX25_I;
 		frame[0] |= (ax25->vs << 1);
-		frame[1] = (poll_bit) ? EPF : 0;
+		frame[1] = (poll_bit) ? AX25_EPF : 0;
 		frame[1] |= (ax25->vr << 1);
 	}
 
-	ax25_transmit_buffer(ax25, skb, C_COMMAND);	
+	ax25->idletimer = ax25->idle;
+
+	ax25_transmit_buffer(ax25, skb, AX25_COMMAND);
 }
 
 void ax25_kick(ax25_cb *ax25)
@@ -193,8 +178,8 @@
 	start = (skb_peek(&ax25->ack_queue) == NULL) ? ax25->va : ax25->vs;
 	end   = (ax25->va + ax25->window) % ax25->modulus;
 
-	if (!(ax25->condition & PEER_RX_BUSY_CONDITION) &&
-	    start != end                                   &&
+	if (!(ax25->condition & AX25_COND_PEER_RX_BUSY) &&
+	    start != end                                &&
 	    skb_peek(&ax25->write_queue) != NULL) {
 
 		ax25->vs = start;
@@ -216,18 +201,20 @@
 				break;
 			}
 
+			skbn->sk = skb->sk;
+
+			if (skbn->sk != NULL)
+				atomic_add(skbn->truesize, &skbn->sk->wmem_alloc);
+
 			next = (ax25->vs + 1) % ax25->modulus;
-#ifdef notdef
-			last = (next == end) || skb_peek(&ax25->write_queue) == NULL;
-#else
 			last = (next == end);
-#endif
+
 			/*
 			 * Transmit the frame copy.
 			 * bke 960114: do not set the Poll bit on the last frame
 			 * in DAMA mode.
 			 */
-			ax25_send_iframe(ax25, skbn, (last && !ax25->dama_slave) ? POLLON : POLLOFF);
+			ax25_send_iframe(ax25, skbn, (last && !ax25->dama_slave) ? AX25_POLLON : AX25_POLLOFF);
 
 			ax25->vs = next;
 
@@ -235,12 +222,10 @@
 			 * Requeue the original data frame.
 			 */
 			skb_queue_tail(&ax25->ack_queue, skb);
-#ifdef notdef
-		} while (!last);
-#else
+
 		} while (!last && (skb = skb_dequeue(&ax25->write_queue)) != NULL);
-#endif
-		ax25->condition &= ~ACK_PENDING_CONDITION;
+
+		ax25->condition &= ~AX25_COND_ACK_PENDING;
 
 		if (ax25->t1timer == 0) {
 			ax25->t3timer = 0;
@@ -256,13 +241,7 @@
 	unsigned char *ptr;
 
 	if (ax25->device == NULL) {
-		if (ax25->sk != NULL) {
-			ax25->sk->state = TCP_CLOSE;
-			ax25->sk->err   = ENETUNREACH;
-			if (!ax25->sk->dead)
-				ax25->sk->state_change(ax25->sk);
-			ax25->sk->dead  = 1;
-		}
+		ax25_disconnect(ax25, ENETUNREACH);
 		return;
 	}
 
@@ -276,8 +255,6 @@
 	ptr = skb_push(skb, size_ax25_addr(ax25->digipeat));
 	build_ax25_addr(ptr, &ax25->source_addr, &ax25->dest_addr, ax25->digipeat, type, ax25->modulus);
 
-	skb->arp = 1;
-
 	ax25_queue_xmit(skb, ax25->device, SOPRI_NORMAL);
 }
 
@@ -296,12 +273,11 @@
 	ax25->condition = 0x00;
 	ax25->n2count   = 0;
 
-	if (ax25->modulus == MODULUS) {
-		ax25_send_control(ax25, SABM, POLLON, C_COMMAND);
-	} else {
-		ax25_send_control(ax25, SABME, POLLON, C_COMMAND);
-	}
-	
+	if (ax25->modulus == AX25_MODULUS)
+		ax25_send_control(ax25, AX25_SABM, AX25_POLLON, AX25_COMMAND);
+	else
+		ax25_send_control(ax25, AX25_SABME, AX25_POLLON, AX25_COMMAND);
+
 	ax25->t3timer = 0;
 	ax25->t2timer = 0;
 	ax25->t1timer = ax25->t1 = ax25_calculate_t1(ax25);
@@ -309,34 +285,34 @@
 
 void ax25_transmit_enquiry(ax25_cb *ax25)
 {
-	if (ax25->condition & OWN_RX_BUSY_CONDITION)
-		ax25_send_control(ax25, RNR, POLLON, C_COMMAND);
+	if (ax25->condition & AX25_COND_OWN_RX_BUSY)
+		ax25_send_control(ax25, AX25_RNR, AX25_POLLON, AX25_COMMAND);
 	else
-		ax25_send_control(ax25, RR, POLLON, C_COMMAND);
+		ax25_send_control(ax25, AX25_RR, AX25_POLLON, AX25_COMMAND);
 
-	ax25->condition &= ~ACK_PENDING_CONDITION;
+	ax25->condition &= ~AX25_COND_ACK_PENDING;
 
 	ax25->t1timer = ax25->t1 = ax25_calculate_t1(ax25);
 }
  	
 void ax25_enquiry_response(ax25_cb *ax25)
 {
-	if (ax25->condition & OWN_RX_BUSY_CONDITION)
-		ax25_send_control(ax25, RNR, POLLON, C_RESPONSE);
+	if (ax25->condition & AX25_COND_OWN_RX_BUSY)
+		ax25_send_control(ax25, AX25_RNR, AX25_POLLON, AX25_RESPONSE);
 	else
-		ax25_send_control(ax25, RR, POLLON, C_RESPONSE);
+		ax25_send_control(ax25, AX25_RR, AX25_POLLON, AX25_RESPONSE);
 
-	ax25->condition &= ~ACK_PENDING_CONDITION;
+	ax25->condition &= ~AX25_COND_ACK_PENDING;
 }
 
 void ax25_timeout_response(ax25_cb *ax25)
 {
-	if (ax25->condition & OWN_RX_BUSY_CONDITION)
-		ax25_send_control(ax25, RNR, POLLOFF, C_RESPONSE);
+	if (ax25->condition & AX25_COND_OWN_RX_BUSY)
+		ax25_send_control(ax25, AX25_RNR, AX25_POLLOFF, AX25_RESPONSE);
 	else
-		ax25_send_control(ax25, RR, POLLOFF, C_RESPONSE);
+		ax25_send_control(ax25, AX25_RR, AX25_POLLOFF, AX25_RESPONSE);
 
-	ax25->condition &= ~ACK_PENDING_CONDITION;
+	ax25->condition &= ~AX25_COND_ACK_PENDING;
 }
 
 void ax25_check_iframes_acked(ax25_cb *ax25, unsigned short nr)
@@ -355,50 +331,37 @@
 }
 
 /*
- *	dl1bke 960114: shouldn't ax25/dama_check_need_response reside as
- *                static inline void ...() in ax25.h, should it? ;-)
- */
-void ax25_check_need_response(ax25_cb *ax25, int type, int pf)
-{
-	if (!ax25->dama_slave && type == C_COMMAND && pf)
-		ax25_enquiry_response(ax25);
-}
-
-/*
  *	dl1bke 960114: transmit I frames on DAMA poll
  */
 void dama_enquiry_response(ax25_cb *ax25)
 {
 	ax25_cb *ax25o;
-	
-	if (!(ax25->condition & PEER_RX_BUSY_CONDITION)) {
+
+	if (!(ax25->condition & AX25_COND_PEER_RX_BUSY)) {
 		ax25_requeue_frames(ax25);
 		ax25_kick(ax25);
 	}
 
-	if (ax25->state == AX25_STATE_1 || ax25->state == AX25_STATE_2 ||
-	    skb_peek(&ax25->ack_queue) != NULL) {
+	if (ax25->state == AX25_STATE_1 || ax25->state == AX25_STATE_2 || skb_peek(&ax25->ack_queue) != NULL)
 		ax25_t1_timeout(ax25);
-	} else {
+	else
 		ax25->n2count = 0;
-	}
-	
+
 	ax25->t3timer = ax25->t3;
-	
 
 	/* The FLEXNET DAMA master implementation refuses to send us ANY */
 	/* I frame for this connection if we send a REJ here, probably   */
 	/* due to its frame collector scheme? A simple RR or  RNR will   */
 	/* invoke the retransmission, and in fact REJs are superfluous   */
 	/* in DAMA mode anyway...					 */
-	
+
 #if 0
-	if (ax25->condition & REJECT_CONDITION)
-		ax25_send_control(ax25, REJ, POLLOFF, C_RESPONSE);
+	if (ax25->condition & AX25_COND_REJECT)
+		ax25_send_control(ax25, AX25_REJ, AX25_POLLOFF, AX25_RESPONSE);
 	else
-#endif	
+#endif
 		ax25_enquiry_response(ax25);
-		
+
 	/* Note that above response to the poll could be sent behind the  */
 	/* transmissions of the other channels as well... This version    */	
 	/* gives better performance on FLEXNET nodes. (Why, Gunter?)	  */
@@ -417,27 +380,19 @@
 
 		if (!ax25o->dama_slave)
 			continue;
-			
-		if ( !(ax25o->condition & PEER_RX_BUSY_CONDITION) && 
-		     (ax25o->state == AX25_STATE_3 || 
-		     (ax25o->state == AX25_STATE_4 && ax25o->t1timer == 0))) {
+
+		if (!(ax25o->condition & AX25_COND_PEER_RX_BUSY) && 
+		    (ax25o->state == AX25_STATE_3 || 
+		    (ax25o->state == AX25_STATE_4 && ax25o->t1timer == 0))) {
 			ax25_requeue_frames(ax25o);
 			ax25_kick(ax25o);
 		}
-		
-		if (ax25o->state == AX25_STATE_1 || ax25o->state == AX25_STATE_2 ||
-		    skb_peek(&ax25o->ack_queue) != NULL) {
+
+		if (ax25o->state == AX25_STATE_1 || ax25o->state == AX25_STATE_2 || skb_peek(&ax25o->ack_queue) != NULL)
 			ax25_t1_timeout(ax25o);
-		}
 
 		ax25o->t3timer = ax25o->t3;
 	}
-}
-
-void dama_check_need_response(ax25_cb *ax25, int type, int pf)
-{
-	if (ax25->dama_slave && type == C_COMMAND && pf)
-		dama_enquiry_response(ax25);
 }
 
 void dama_establish_data_link(ax25_cb *ax25)

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