mirror of
https://github.com/xcat2/xNBA.git
synced 2025-01-27 11:29:03 +00:00
[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()).
This commit is contained in:
parent
46da51703a
commit
8ae1cac050
@ -27,6 +27,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Dummy transfer metadata
|
||||
*
|
||||
* This gets passed to xfer_interface::deliver_iob() and equivalents
|
||||
* when no metadata is available.
|
||||
*/
|
||||
static struct xfer_metadata dummy_metadata;
|
||||
|
||||
/**
|
||||
* Close data transfer interface
|
||||
*
|
||||
@ -159,7 +167,6 @@ int xfer_deliver_iob_meta ( struct xfer_interface *xfer,
|
||||
*/
|
||||
int xfer_deliver_iob ( struct xfer_interface *xfer,
|
||||
struct io_buffer *iobuf ) {
|
||||
static struct xfer_metadata dummy_metadata;
|
||||
return xfer_deliver_iob_meta ( xfer, iobuf, &dummy_metadata );
|
||||
}
|
||||
|
||||
@ -366,7 +373,7 @@ int xfer_deliver_as_iob ( struct xfer_interface *xfer,
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy ( iob_put ( iobuf, len ), data, len );
|
||||
return xfer->op->deliver_iob ( xfer, iobuf, NULL );
|
||||
return xfer->op->deliver_iob ( xfer, iobuf, &dummy_metadata );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1033,7 +1033,7 @@ static size_t tcp_xfer_window ( struct xfer_interface *xfer ) {
|
||||
*
|
||||
* @v xfer Data transfer interface
|
||||
* @v iobuf Datagram I/O buffer
|
||||
* @v meta Data transfer metadata, or NULL
|
||||
* @v meta Data transfer metadata
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int tcp_xfer_deliver_iob ( struct xfer_interface *xfer,
|
||||
|
@ -380,7 +380,7 @@ static void ftp_data_closed ( struct xfer_interface *data, int rc ) {
|
||||
*
|
||||
* @v xfer FTP data channel interface
|
||||
* @v iobuf I/O buffer
|
||||
* @v meta Data transfer metadata, or NULL
|
||||
* @v meta Data transfer metadata
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int ftp_data_deliver_iob ( struct xfer_interface *data,
|
||||
|
@ -321,7 +321,7 @@ static int http_rx_data ( struct http_request *http,
|
||||
*
|
||||
* @v socket Transport layer interface
|
||||
* @v iobuf I/O buffer
|
||||
* @v meta Data transfer metadata, or NULL
|
||||
* @v meta Data transfer metadata
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int http_socket_deliver_iob ( struct xfer_interface *socket,
|
||||
|
@ -390,7 +390,7 @@ static struct io_buffer * udp_alloc_iob ( struct xfer_interface *xfer,
|
||||
*
|
||||
* @v xfer Data transfer interface
|
||||
* @v iobuf Datagram I/O buffer
|
||||
* @v meta Data transfer metadata, or NULL
|
||||
* @v meta Data transfer metadata
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int udp_xfer_deliver_iob ( struct xfer_interface *xfer,
|
||||
@ -398,19 +398,10 @@ static int udp_xfer_deliver_iob ( struct xfer_interface *xfer,
|
||||
struct xfer_metadata *meta ) {
|
||||
struct udp_connection *udp =
|
||||
container_of ( xfer, struct udp_connection, xfer );
|
||||
struct sockaddr_tcpip *src = NULL;
|
||||
struct sockaddr_tcpip *dest = NULL;
|
||||
struct net_device *netdev = NULL;
|
||||
|
||||
/* Apply xfer metadata */
|
||||
if ( meta ) {
|
||||
src = ( struct sockaddr_tcpip * ) meta->src;
|
||||
dest = ( struct sockaddr_tcpip * ) meta->dest;
|
||||
netdev = meta->netdev;
|
||||
}
|
||||
|
||||
/* Transmit data, if possible */
|
||||
udp_tx ( udp, iobuf, src, dest, netdev );
|
||||
udp_tx ( udp, iobuf, ( ( struct sockaddr_tcpip * ) meta->src ),
|
||||
( ( struct sockaddr_tcpip * ) meta->dest ), meta->netdev );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1052,12 +1052,6 @@ static int dhcp_deliver_iob ( struct xfer_interface *xfer,
|
||||
int rc = 0;
|
||||
|
||||
/* Sanity checks */
|
||||
if ( ! meta ) {
|
||||
DBGC ( dhcp, "DHCP %p received packet without metadata\n",
|
||||
dhcp );
|
||||
rc = -EINVAL;
|
||||
goto err_no_meta;
|
||||
}
|
||||
if ( ! meta->src ) {
|
||||
DBGC ( dhcp, "DHCP %p received packet without source port\n",
|
||||
dhcp );
|
||||
@ -1106,7 +1100,6 @@ static int dhcp_deliver_iob ( struct xfer_interface *xfer,
|
||||
dhcppkt_put ( dhcppkt );
|
||||
err_alloc_dhcppkt:
|
||||
err_no_src:
|
||||
err_no_meta:
|
||||
free_iob ( iobuf );
|
||||
return rc;
|
||||
}
|
||||
|
@ -839,7 +839,7 @@ static int tftp_rx_error ( struct tftp_request *tftp, void *buf, size_t len ) {
|
||||
*
|
||||
* @v tftp TFTP connection
|
||||
* @v iobuf I/O buffer
|
||||
* @v meta Transfer metadata, or NULL
|
||||
* @v meta Transfer metadata
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int tftp_rx ( struct tftp_request *tftp,
|
||||
@ -856,11 +856,6 @@ static int tftp_rx ( struct tftp_request *tftp,
|
||||
"%zd\n", tftp, len );
|
||||
goto done;
|
||||
}
|
||||
if ( ! meta ) {
|
||||
DBGC ( tftp, "TFTP %p received packet without metadata\n",
|
||||
tftp );
|
||||
goto done;
|
||||
}
|
||||
if ( ! meta->src ) {
|
||||
DBGC ( tftp, "TFTP %p received packet without source port\n",
|
||||
tftp );
|
||||
@ -907,7 +902,7 @@ static int tftp_rx ( struct tftp_request *tftp,
|
||||
*
|
||||
* @v socket Transport layer interface
|
||||
* @v iobuf I/O buffer
|
||||
* @v meta Transfer metadata, or NULL
|
||||
* @v meta Transfer metadata
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int tftp_socket_deliver_iob ( struct xfer_interface *socket,
|
||||
@ -951,7 +946,7 @@ static struct xfer_interface_operations tftp_socket_operations = {
|
||||
*
|
||||
* @v mc_socket Multicast transport layer interface
|
||||
* @v iobuf I/O buffer
|
||||
* @v meta Transfer metadata, or NULL
|
||||
* @v meta Transfer metadata
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int tftp_mc_socket_deliver_iob ( struct xfer_interface *mc_socket,
|
||||
|
Loading…
x
Reference in New Issue
Block a user