Sfoglia il codice sorgente

Reserve space for lower-layer headers when allocating packet buffer.

Use pkb_available() rather than pkb_len() (which will always return 0
on a freshly allocated buffer).

udp_send() should assume that the buffer has already been allocated.
tags/v0.9.3
Michael Brown 18 anni fa
parent
commit
ab633f6a73
1 ha cambiato i file con 5 aggiunte e 33 eliminazioni
  1. 5
    33
      src/net/udp.c

+ 5
- 33
src/net/udp.c Vedi File

@@ -87,24 +87,6 @@ void udp_init ( struct udp_connection *conn, struct udp_operations *udp_op ) {
87 87
 	}
88 88
 }
89 89
 
90
-/**
91
- * Allocate space to the UDP buffer
92
- *
93
- * @v conn      UDP connection
94
- * @v len       Length to allocate
95
- * @ret rc      Status
96
- *
97
- * Allocate "len" amount of space in the transmit buffer
98
- */
99
-int udp_buf_alloc ( struct udp_connection *conn, size_t len ) {
100
-	if ( conn->tx_pkb != NULL ) {
101
-		free_pkb ( conn->tx_pkb );
102
-		conn->tx_pkb = NULL;
103
-	}
104
-	conn->tx_pkb = alloc_pkb ( len < UDP_MIN_TXPKB ? UDP_MIN_TXPKB : len );
105
-	return !conn ? -ENOMEM : 0;
106
-}
107
-
108 90
 /**
109 91
  * User request to send data via a UDP connection
110 92
  *
@@ -120,11 +102,12 @@ int udp_senddata ( struct udp_connection *conn ) {
120 102
 							UDP_MAX_TXPKB );
121 103
 		return -ENOMEM;
122 104
 	}
123
-	conn->udp_op->senddata ( conn, conn->tx_pkb, pkb_len ( conn->tx_pkb ) );
105
+	pkb_reserve ( conn->tx_pkb, UDP_MAX_HLEN );
106
+	conn->udp_op->senddata ( conn, conn->tx_pkb, 
107
+				 pkb_available ( conn->tx_pkb ) );
124 108
 	return 0;
125 109
 }
126 110
 		
127
-
128 111
 /**
129 112
  * Transmit data via a UDP connection
130 113
  *
@@ -140,20 +123,9 @@ int udp_send ( struct udp_connection *conn, const void *data, size_t len ) {
140 123
        	struct udp_header *udphdr;		/* UDP header */
141 124
 	struct sockaddr *sock = &conn->sin;	/* Destination sockaddr */
142 125
 	uint16_t *dest;
143
-	int rc;
144 126
 
145
-	/* Copy data into packet buffer, if necessary */
146
-	if ( data != conn->tx_pkb->data ) {
147
-		/* Allocate space for data and lower layer headers */
148
-		if ( ( rc = udp_buf_alloc ( conn, len + UDP_MAX_HLEN ) ) != 0 ) {
149
-			DBG ( "Error allocating buffer" );
150
-			return rc;
151
-		}
152
-
153
-		/* Reserve space for the headers and copy contents */
154
-		pkb_reserve ( conn->tx_pkb, UDP_MAX_HLEN );
155
-		memmove ( pkb_put ( conn->tx_pkb, len ), data, len );
156
-	}
127
+	/* Copy payload */
128
+	memmove ( pkb_put ( conn->tx_pkb, len ), data, len );
157 129
 
158 130
 	/*
159 131
 	 * Add the UDP header

Loading…
Annulla
Salva