Browse Source

[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 years ago
parent
commit
8ae1cac050
7 changed files with 18 additions and 32 deletions
  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 View File

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
  * Close data transfer interface
39
  * Close data transfer interface
32
  *
40
  *
159
  */
167
  */
160
 int xfer_deliver_iob ( struct xfer_interface *xfer,
168
 int xfer_deliver_iob ( struct xfer_interface *xfer,
161
 		       struct io_buffer *iobuf ) {
169
 		       struct io_buffer *iobuf ) {
162
-	static struct xfer_metadata dummy_metadata;
163
 	return xfer_deliver_iob_meta ( xfer, iobuf, &dummy_metadata );
170
 	return xfer_deliver_iob_meta ( xfer, iobuf, &dummy_metadata );
164
 }
171
 }
165
 
172
 
366
 		return -ENOMEM;
373
 		return -ENOMEM;
367
 
374
 
368
 	memcpy ( iob_put ( iobuf, len ), data, len );
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 View File

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

+ 1
- 1
src/net/tcp/ftp.c View File

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

+ 1
- 1
src/net/tcp/http.c View File

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

+ 3
- 12
src/net/udp.c View File

390
  *
390
  *
391
  * @v xfer		Data transfer interface
391
  * @v xfer		Data transfer interface
392
  * @v iobuf		Datagram I/O buffer
392
  * @v iobuf		Datagram I/O buffer
393
- * @v meta		Data transfer metadata, or NULL
393
+ * @v meta		Data transfer metadata
394
  * @ret rc		Return status code
394
  * @ret rc		Return status code
395
  */
395
  */
396
 static int udp_xfer_deliver_iob ( struct xfer_interface *xfer,
396
 static int udp_xfer_deliver_iob ( struct xfer_interface *xfer,
398
 				  struct xfer_metadata *meta ) {
398
 				  struct xfer_metadata *meta ) {
399
 	struct udp_connection *udp =
399
 	struct udp_connection *udp =
400
 		container_of ( xfer, struct udp_connection, xfer );
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
 	/* Transmit data, if possible */
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
 	return 0;
406
 	return 0;
416
 }
407
 }

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

1052
 	int rc = 0;
1052
 	int rc = 0;
1053
 
1053
 
1054
 	/* Sanity checks */
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
 	if ( ! meta->src ) {
1055
 	if ( ! meta->src ) {
1062
 		DBGC ( dhcp, "DHCP %p received packet without source port\n",
1056
 		DBGC ( dhcp, "DHCP %p received packet without source port\n",
1063
 		       dhcp );
1057
 		       dhcp );
1106
 	dhcppkt_put ( dhcppkt );
1100
 	dhcppkt_put ( dhcppkt );
1107
  err_alloc_dhcppkt:
1101
  err_alloc_dhcppkt:
1108
  err_no_src:
1102
  err_no_src:
1109
- err_no_meta:
1110
 	free_iob ( iobuf );
1103
 	free_iob ( iobuf );
1111
 	return rc;
1104
 	return rc;
1112
 }
1105
 }

+ 3
- 8
src/net/udp/tftp.c View File

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

Loading…
Cancel
Save