Procházet zdrojové kódy

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 před 18 roky
rodič
revize
ffe0e24249
4 změnil soubory, kde provedl 19 přidání a 36 odebrání
  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 Zobrazit soubor

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

+ 4
- 3
src/interface/pxe/pxe_udp.c Zobrazit soubor

52
  * @v conn			UDP connection
52
  * @v conn			UDP connection
53
  * @v data			Temporary data buffer
53
  * @v data			Temporary data buffer
54
  * @v len			Size of temporary data buffer
54
  * @v len			Size of temporary data buffer
55
+ * @ret rc			Return status code
55
  *
56
  *
56
  * Sends the packet belonging to the current pxenv_udp_write()
57
  * Sends the packet belonging to the current pxenv_udp_write()
57
  * operation.
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
 	struct pxe_udp_connection *pxe_udp = udp_to_pxe ( conn );
62
 	struct pxe_udp_connection *pxe_udp = udp_to_pxe ( conn );
62
 	struct s_PXENV_UDP_WRITE *pxenv_udp_write = pxe_udp->pxenv_udp_write;
63
 	struct s_PXENV_UDP_WRITE *pxenv_udp_write = pxe_udp->pxenv_udp_write;
63
 	userptr_t buffer;
64
 	userptr_t buffer;
68
 	if ( len > pxenv_udp_write->buffer_size )
69
 	if ( len > pxenv_udp_write->buffer_size )
69
 		len = pxenv_udp_write->buffer_size;
70
 		len = pxenv_udp_write->buffer_size;
70
 	copy_from_user ( data, buffer, 0, len );
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 Zobrazit soubor

66
 	memcpy ( &conn->peer, peer, sizeof ( conn->peer ) );
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
  * Open a local port
70
  * Open a local port
83
  *
71
  *
140
 		return -ENOMEM;
128
 		return -ENOMEM;
141
 	}
129
 	}
142
 	pkb_reserve ( conn->tx_pkb, UDP_MAX_HLEN );
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
 			/* Bound to local port and local port doesn't match */
258
 			/* Bound to local port and local port doesn't match */
272
 			continue;
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
 		/* Strip off the UDP header */
262
 		/* Strip off the UDP header */
284
 		pkb_pull ( pkb, sizeof ( *udphdr ) );
263
 		pkb_pull ( pkb, sizeof ( *udphdr ) );

+ 10
- 7
src/net/udp/dhcp.c Zobrazit soubor

508
  * @v conn		UDP connection
508
  * @v conn		UDP connection
509
  * @v buf		Temporary data buffer
509
  * @v buf		Temporary data buffer
510
  * @v len		Length of temporary data buffer
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
 	struct dhcp_session *dhcp = udp_to_dhcp ( conn );
515
 	struct dhcp_session *dhcp = udp_to_dhcp ( conn );
515
 	struct dhcp_packet dhcppkt;
516
 	struct dhcp_packet dhcppkt;
516
 	int rc;
517
 	int rc;
524
 	if ( ( rc = create_dhcp_packet ( dhcp, dhcp->state, buf, len,
525
 	if ( ( rc = create_dhcp_packet ( dhcp, dhcp->state, buf, len,
525
 					 &dhcppkt ) ) != 0 ) {
526
 					 &dhcppkt ) ) != 0 ) {
526
 		DBG ( "Could not create DHCP packet\n" );
527
 		DBG ( "Could not create DHCP packet\n" );
527
-		return;
528
+		return rc;
528
 	}
529
 	}
529
 
530
 
530
 	/* Copy in options common to all requests */
531
 	/* Copy in options common to all requests */
531
 	if ( ( rc = copy_dhcp_packet_options ( &dhcppkt,
532
 	if ( ( rc = copy_dhcp_packet_options ( &dhcppkt,
532
 					       &dhcp_request_options ) ) != 0){
533
 					       &dhcp_request_options ) ) != 0){
533
 		DBG ( "Could not set common DHCP options\n" );
534
 		DBG ( "Could not set common DHCP options\n" );
534
-		return;
535
+		return rc;
535
 	}
536
 	}
536
 
537
 
537
 	/* Copy any required options from previous server repsonse */
538
 	/* Copy any required options from previous server repsonse */
540
 					    DHCP_SERVER_IDENTIFIER,
541
 					    DHCP_SERVER_IDENTIFIER,
541
 					    DHCP_SERVER_IDENTIFIER ) ) != 0 ) {
542
 					    DHCP_SERVER_IDENTIFIER ) ) != 0 ) {
542
 			DBG ( "Could not set server identifier option\n" );
543
 			DBG ( "Could not set server identifier option\n" );
543
-			return;
544
+			return rc;
544
 		}
545
 		}
545
 		if ( ( rc = copy_dhcp_packet_option ( &dhcppkt, dhcp->options,
546
 		if ( ( rc = copy_dhcp_packet_option ( &dhcppkt, dhcp->options,
546
 					    DHCP_EB_YIADDR,
547
 					    DHCP_EB_YIADDR,
547
 					    DHCP_REQUESTED_ADDRESS ) ) != 0 ) {
548
 					    DHCP_REQUESTED_ADDRESS ) ) != 0 ) {
548
 			DBG ( "Could not set requested address option\n" );
549
 			DBG ( "Could not set requested address option\n" );
549
-			return;
550
+			return rc;
550
 		}
551
 		}
551
 	}
552
 	}
552
 
553
 
554
 	if ( ( rc = udp_sendto ( conn, &sa_dhcp_server.st,
555
 	if ( ( rc = udp_sendto ( conn, &sa_dhcp_server.st,
555
 				 dhcppkt.dhcphdr, dhcppkt.len ) ) != 0 ) {
556
 				 dhcppkt.dhcphdr, dhcppkt.len ) ) != 0 ) {
556
 		DBG ( "Could not transmit UDP packet\n" );
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
 /**

Načítá se…
Zrušit
Uložit