Przeglądaj źródła

[xfer] Make consistent assumptions that xfer metadata can never be NULL

The documentation in xfer.h and xfer.c does not say that the metadata
parameter is optional in calls such as xfer_deliver_iob_meta() and the
deliver_iob() method.  However, some code in net/ is prepared to
accept a NULL pointer, and xfer_deliver_as_iob() passes a NULL pointer
directly to the deliver_iob() method.

Fix this mess of conflicting assumptions by making everything assume
that the metadata parameter is mandatory, and fixing
xfer_deliver_as_iob() to pass in a dummy metadata structure (as is
already done in xfer_deliver_iob()).
tags/v0.9.7
Michael Brown 16 lat temu
rodzic
commit
8ae1cac050
7 zmienionych plików z 18 dodań i 32 usunięć
  1. 9
    2
      src/core/xfer.c
  2. 1
    1
      src/net/tcp.c
  3. 1
    1
      src/net/tcp/ftp.c
  4. 1
    1
      src/net/tcp/http.c
  5. 3
    12
      src/net/udp.c
  6. 0
    7
      src/net/udp/dhcp.c
  7. 3
    8
      src/net/udp/tftp.c

+ 9
- 2
src/core/xfer.c Wyświetl plik

@@ -27,6 +27,14 @@
27 27
  *
28 28
  */
29 29
 
30
+/**
31
+ * Dummy transfer metadata
32
+ *
33
+ * This gets passed to xfer_interface::deliver_iob() and equivalents
34
+ * when no metadata is available.
35
+ */
36
+static struct xfer_metadata dummy_metadata;
37
+
30 38
 /**
31 39
  * Close data transfer interface
32 40
  *
@@ -159,7 +167,6 @@ int xfer_deliver_iob_meta ( struct xfer_interface *xfer,
159 167
  */
160 168
 int xfer_deliver_iob ( struct xfer_interface *xfer,
161 169
 		       struct io_buffer *iobuf ) {
162
-	static struct xfer_metadata dummy_metadata;
163 170
 	return xfer_deliver_iob_meta ( xfer, iobuf, &dummy_metadata );
164 171
 }
165 172
 
@@ -366,7 +373,7 @@ int xfer_deliver_as_iob ( struct xfer_interface *xfer,
366 373
 		return -ENOMEM;
367 374
 
368 375
 	memcpy ( iob_put ( iobuf, len ), data, len );
369
-	return xfer->op->deliver_iob ( xfer, iobuf, NULL );
376
+	return xfer->op->deliver_iob ( xfer, iobuf, &dummy_metadata );
370 377
 }
371 378
 
372 379
 /**

+ 1
- 1
src/net/tcp.c Wyświetl plik

@@ -1033,7 +1033,7 @@ static size_t tcp_xfer_window ( struct xfer_interface *xfer ) {
1033 1033
  *
1034 1034
  * @v xfer		Data transfer interface
1035 1035
  * @v iobuf		Datagram I/O buffer
1036
- * @v meta		Data transfer metadata, or NULL
1036
+ * @v meta		Data transfer metadata
1037 1037
  * @ret rc		Return status code
1038 1038
  */
1039 1039
 static int tcp_xfer_deliver_iob ( struct xfer_interface *xfer,

+ 1
- 1
src/net/tcp/ftp.c Wyświetl plik

@@ -380,7 +380,7 @@ static void ftp_data_closed ( struct xfer_interface *data, int rc ) {
380 380
  *
381 381
  * @v xfer		FTP data channel interface
382 382
  * @v iobuf		I/O buffer
383
- * @v meta		Data transfer metadata, or NULL
383
+ * @v meta		Data transfer metadata
384 384
  * @ret rc		Return status code
385 385
  */
386 386
 static int ftp_data_deliver_iob ( struct xfer_interface *data,

+ 1
- 1
src/net/tcp/http.c Wyświetl plik

@@ -321,7 +321,7 @@ static int http_rx_data ( struct http_request *http,
321 321
  *
322 322
  * @v socket		Transport layer interface
323 323
  * @v iobuf		I/O buffer
324
- * @v meta		Data transfer metadata, or NULL
324
+ * @v meta		Data transfer metadata
325 325
  * @ret rc		Return status code
326 326
  */
327 327
 static int http_socket_deliver_iob ( struct xfer_interface *socket,

+ 3
- 12
src/net/udp.c Wyświetl plik

@@ -390,7 +390,7 @@ static struct io_buffer * udp_alloc_iob ( struct xfer_interface *xfer,
390 390
  *
391 391
  * @v xfer		Data transfer interface
392 392
  * @v iobuf		Datagram I/O buffer
393
- * @v meta		Data transfer metadata, or NULL
393
+ * @v meta		Data transfer metadata
394 394
  * @ret rc		Return status code
395 395
  */
396 396
 static int udp_xfer_deliver_iob ( struct xfer_interface *xfer,
@@ -398,19 +398,10 @@ static int udp_xfer_deliver_iob ( struct xfer_interface *xfer,
398 398
 				  struct xfer_metadata *meta ) {
399 399
 	struct udp_connection *udp =
400 400
 		container_of ( xfer, struct udp_connection, xfer );
401
-	struct sockaddr_tcpip *src = NULL;
402
-	struct sockaddr_tcpip *dest = NULL;
403
-	struct net_device *netdev = NULL;
404
-
405
-	/* Apply xfer metadata */
406
-	if ( meta ) {
407
-		src = ( struct sockaddr_tcpip * ) meta->src;
408
-		dest = ( struct sockaddr_tcpip * ) meta->dest;
409
-		netdev = meta->netdev;
410
-	}
411 401
 
412 402
 	/* Transmit data, if possible */
413
-	udp_tx ( udp, iobuf, src, dest, netdev );
403
+	udp_tx ( udp, iobuf, ( ( struct sockaddr_tcpip * ) meta->src ),
404
+		 ( ( struct sockaddr_tcpip * ) meta->dest ), meta->netdev );
414 405
 
415 406
 	return 0;
416 407
 }

+ 0
- 7
src/net/udp/dhcp.c Wyświetl plik

@@ -1052,12 +1052,6 @@ static int dhcp_deliver_iob ( struct xfer_interface *xfer,
1052 1052
 	int rc = 0;
1053 1053
 
1054 1054
 	/* Sanity checks */
1055
-	if ( ! meta ) {
1056
-		DBGC ( dhcp, "DHCP %p received packet without metadata\n",
1057
-		       dhcp );
1058
-		rc = -EINVAL;
1059
-		goto err_no_meta;
1060
-	}
1061 1055
 	if ( ! meta->src ) {
1062 1056
 		DBGC ( dhcp, "DHCP %p received packet without source port\n",
1063 1057
 		       dhcp );
@@ -1106,7 +1100,6 @@ static int dhcp_deliver_iob ( struct xfer_interface *xfer,
1106 1100
 	dhcppkt_put ( dhcppkt );
1107 1101
  err_alloc_dhcppkt:
1108 1102
  err_no_src:
1109
- err_no_meta:
1110 1103
 	free_iob ( iobuf );
1111 1104
 	return rc;
1112 1105
 }

+ 3
- 8
src/net/udp/tftp.c Wyświetl plik

@@ -839,7 +839,7 @@ static int tftp_rx_error ( struct tftp_request *tftp, void *buf, size_t len ) {
839 839
  *
840 840
  * @v tftp		TFTP connection
841 841
  * @v iobuf		I/O buffer
842
- * @v meta		Transfer metadata, or NULL
842
+ * @v meta		Transfer metadata
843 843
  * @ret rc		Return status code
844 844
  */
845 845
 static int tftp_rx ( struct tftp_request *tftp,
@@ -856,11 +856,6 @@ static int tftp_rx ( struct tftp_request *tftp,
856 856
 		       "%zd\n", tftp, len );
857 857
 		goto done;
858 858
 	}
859
-	if ( ! meta ) {
860
-		DBGC ( tftp, "TFTP %p received packet without metadata\n",
861
-		       tftp );
862
-		goto done;
863
-	}
864 859
 	if ( ! meta->src ) {
865 860
 		DBGC ( tftp, "TFTP %p received packet without source port\n",
866 861
 		       tftp );
@@ -907,7 +902,7 @@ static int tftp_rx ( struct tftp_request *tftp,
907 902
  *
908 903
  * @v socket		Transport layer interface
909 904
  * @v iobuf		I/O buffer
910
- * @v meta		Transfer metadata, or NULL
905
+ * @v meta		Transfer metadata
911 906
  * @ret rc		Return status code
912 907
  */
913 908
 static int tftp_socket_deliver_iob ( struct xfer_interface *socket,
@@ -951,7 +946,7 @@ static struct xfer_interface_operations tftp_socket_operations = {
951 946
  *
952 947
  * @v mc_socket		Multicast transport layer interface
953 948
  * @v iobuf		I/O buffer
954
- * @v meta		Transfer metadata, or NULL
949
+ * @v meta		Transfer metadata
955 950
  * @ret rc		Return status code
956 951
  */
957 952
 static int tftp_mc_socket_deliver_iob ( struct xfer_interface *mc_socket,

Ładowanie…
Anuluj
Zapisz