Browse Source

Make the UDP senddata() methods return a status code.

udp_connect() now follows the standard BSD sockets semantics and simply
sets the default address for outgoing packets; it doesn't filter incoming
packets.
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
ffe0e24249
4 changed files with 19 additions and 36 deletions
  1. 3
    3
      src/include/gpxe/udp.h
  2. 4
    3
      src/interface/pxe/pxe_udp.c
  3. 2
    23
      src/net/udp.c
  4. 10
    7
      src/net/udp/dhcp.c

+ 3
- 3
src/include/gpxe/udp.h View File

@@ -48,6 +48,7 @@ struct udp_operations {
48 48
 	 * @v conn	UDP connection
49 49
 	 * @v buf	Temporary data buffer
50 50
 	 * @v len	Length of temporary data buffer
51
+	 * @ret rc	Return status code
51 52
 	 *
52 53
 	 * The application may use the temporary data buffer to
53 54
 	 * construct the data to be sent.  Note that merely filling
@@ -56,8 +57,8 @@ struct udp_operations {
56 57
 	 * the buffer is not compulsory; the application may call
57 58
 	 * udp_send() on any block of data.
58 59
 	 */
59
-	void ( * senddata ) ( struct udp_connection *conn, void *buf,
60
-			      size_t len );
60
+	int ( * senddata ) ( struct udp_connection *conn, void *buf,
61
+			     size_t len );
61 62
 	/**
62 63
 	 * New data received
63 64
 	 *
@@ -98,7 +99,6 @@ extern int udp_bind ( struct udp_connection *conn, uint16_t local_port );
98 99
 extern void udp_bind_promisc ( struct udp_connection *conn );
99 100
 extern void udp_connect ( struct udp_connection *conn,
100 101
 			  struct sockaddr_tcpip *peer );
101
-extern void udp_connect_promisc ( struct udp_connection *conn );
102 102
 extern int udp_open ( struct udp_connection *conn, uint16_t local_port );
103 103
 extern void udp_close ( struct udp_connection *conn );
104 104
 

+ 4
- 3
src/interface/pxe/pxe_udp.c View File

@@ -52,12 +52,13 @@ udp_to_pxe ( struct udp_connection *conn ) {
52 52
  * @v conn			UDP connection
53 53
  * @v data			Temporary data buffer
54 54
  * @v len			Size of temporary data buffer
55
+ * @ret rc			Return status code
55 56
  *
56 57
  * Sends the packet belonging to the current pxenv_udp_write()
57 58
  * operation.
58 59
  */
59
-static void pxe_udp_senddata ( struct udp_connection *conn, void *data,
60
-			       size_t len ) {
60
+static int pxe_udp_senddata ( struct udp_connection *conn, void *data,
61
+			      size_t len ) {
61 62
 	struct pxe_udp_connection *pxe_udp = udp_to_pxe ( conn );
62 63
 	struct s_PXENV_UDP_WRITE *pxenv_udp_write = pxe_udp->pxenv_udp_write;
63 64
 	userptr_t buffer;
@@ -68,7 +69,7 @@ static void pxe_udp_senddata ( struct udp_connection *conn, void *data,
68 69
 	if ( len > pxenv_udp_write->buffer_size )
69 70
 		len = pxenv_udp_write->buffer_size;
70 71
 	copy_from_user ( data, buffer, 0, len );
71
-	udp_send ( conn, data, len );
72
+	return udp_send ( conn, data, len );
72 73
 }
73 74
 
74 75
 /**

+ 2
- 23
src/net/udp.c View File

@@ -66,18 +66,6 @@ void udp_connect ( struct udp_connection *conn, struct sockaddr_tcpip *peer ) {
66 66
 	memcpy ( &conn->peer, peer, sizeof ( conn->peer ) );
67 67
 }
68 68
 
69
-/**
70
- * Connect UDP connection to all remote hosts and ports
71
- *
72
- * @v conn		UDP connection
73
- *
74
- * This undoes the effect of a call to udp_connect(), i.e. allows the
75
- * connection to receive packets from all remote hosts and ports.
76
- */
77
-void udp_connect_promisc ( struct udp_connection *conn ) {
78
-	memset ( &conn->peer, 0, sizeof ( conn->peer ) );
79
-}
80
-
81 69
 /**
82 70
  * Open a local port
83 71
  *
@@ -140,9 +128,8 @@ int udp_senddata ( struct udp_connection *conn ) {
140 128
 		return -ENOMEM;
141 129
 	}
142 130
 	pkb_reserve ( conn->tx_pkb, UDP_MAX_HLEN );
143
-	conn->udp_op->senddata ( conn, conn->tx_pkb->data, 
144
-				 pkb_available ( conn->tx_pkb ) );
145
-	return 0;
131
+	return conn->udp_op->senddata ( conn, conn->tx_pkb->data, 
132
+					pkb_available ( conn->tx_pkb ) );
146 133
 }
147 134
 		
148 135
 /**
@@ -271,14 +258,6 @@ static int udp_rx ( struct pk_buff *pkb, struct sockaddr_tcpip *st_src,
271 258
 			/* Bound to local port and local port doesn't match */
272 259
 			continue;
273 260
 		}
274
-		if ( conn->peer.st_family &&
275
-		     ( memcmp ( &conn->peer, st_src,
276
-				sizeof ( conn->peer ) ) != 0 ) ) {
277
-			/* Connected to remote port and remote port
278
-			 * doesn't match
279
-			 */
280
-			continue;
281
-		}
282 261
 		
283 262
 		/* Strip off the UDP header */
284 263
 		pkb_pull ( pkb, sizeof ( *udphdr ) );

+ 10
- 7
src/net/udp/dhcp.c View File

@@ -508,9 +508,10 @@ static union {
508 508
  * @v conn		UDP connection
509 509
  * @v buf		Temporary data buffer
510 510
  * @v len		Length of temporary data buffer
511
+ * @ret rc		Return status code
511 512
  */
512
-static void dhcp_senddata ( struct udp_connection *conn,
513
-			    void *buf, size_t len ) {
513
+static int dhcp_senddata ( struct udp_connection *conn,
514
+			   void *buf, size_t len ) {
514 515
 	struct dhcp_session *dhcp = udp_to_dhcp ( conn );
515 516
 	struct dhcp_packet dhcppkt;
516 517
 	int rc;
@@ -524,14 +525,14 @@ static void dhcp_senddata ( struct udp_connection *conn,
524 525
 	if ( ( rc = create_dhcp_packet ( dhcp, dhcp->state, buf, len,
525 526
 					 &dhcppkt ) ) != 0 ) {
526 527
 		DBG ( "Could not create DHCP packet\n" );
527
-		return;
528
+		return rc;
528 529
 	}
529 530
 
530 531
 	/* Copy in options common to all requests */
531 532
 	if ( ( rc = copy_dhcp_packet_options ( &dhcppkt,
532 533
 					       &dhcp_request_options ) ) != 0){
533 534
 		DBG ( "Could not set common DHCP options\n" );
534
-		return;
535
+		return rc;
535 536
 	}
536 537
 
537 538
 	/* Copy any required options from previous server repsonse */
@@ -540,13 +541,13 @@ static void dhcp_senddata ( struct udp_connection *conn,
540 541
 					    DHCP_SERVER_IDENTIFIER,
541 542
 					    DHCP_SERVER_IDENTIFIER ) ) != 0 ) {
542 543
 			DBG ( "Could not set server identifier option\n" );
543
-			return;
544
+			return rc;
544 545
 		}
545 546
 		if ( ( rc = copy_dhcp_packet_option ( &dhcppkt, dhcp->options,
546 547
 					    DHCP_EB_YIADDR,
547 548
 					    DHCP_REQUESTED_ADDRESS ) ) != 0 ) {
548 549
 			DBG ( "Could not set requested address option\n" );
549
-			return;
550
+			return rc;
550 551
 		}
551 552
 	}
552 553
 
@@ -554,8 +555,10 @@ static void dhcp_senddata ( struct udp_connection *conn,
554 555
 	if ( ( rc = udp_sendto ( conn, &sa_dhcp_server.st,
555 556
 				 dhcppkt.dhcphdr, dhcppkt.len ) ) != 0 ) {
556 557
 		DBG ( "Could not transmit UDP packet\n" );
557
-		return;
558
+		return rc;
558 559
 	}
560
+
561
+	return 0;
559 562
 }
560 563
 
561 564
 /**

Loading…
Cancel
Save