mirror of
https://github.com/ipxe/ipxe
synced 2025-12-19 19:49:45 +03:00
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.
This commit is contained in:
@@ -48,6 +48,7 @@ struct udp_operations {
|
|||||||
* @v conn UDP connection
|
* @v conn UDP connection
|
||||||
* @v buf Temporary data buffer
|
* @v buf Temporary data buffer
|
||||||
* @v len Length of temporary data buffer
|
* @v len Length of temporary data buffer
|
||||||
|
* @ret rc Return status code
|
||||||
*
|
*
|
||||||
* The application may use the temporary data buffer to
|
* The application may use the temporary data buffer to
|
||||||
* construct the data to be sent. Note that merely filling
|
* construct the data to be sent. Note that merely filling
|
||||||
@@ -56,8 +57,8 @@ struct udp_operations {
|
|||||||
* the buffer is not compulsory; the application may call
|
* the buffer is not compulsory; the application may call
|
||||||
* udp_send() on any block of data.
|
* udp_send() on any block of data.
|
||||||
*/
|
*/
|
||||||
void ( * senddata ) ( struct udp_connection *conn, void *buf,
|
int ( * senddata ) ( struct udp_connection *conn, void *buf,
|
||||||
size_t len );
|
size_t len );
|
||||||
/**
|
/**
|
||||||
* New data received
|
* New data received
|
||||||
*
|
*
|
||||||
@@ -98,7 +99,6 @@ extern int udp_bind ( struct udp_connection *conn, uint16_t local_port );
|
|||||||
extern void udp_bind_promisc ( struct udp_connection *conn );
|
extern void udp_bind_promisc ( struct udp_connection *conn );
|
||||||
extern void udp_connect ( struct udp_connection *conn,
|
extern void udp_connect ( struct udp_connection *conn,
|
||||||
struct sockaddr_tcpip *peer );
|
struct sockaddr_tcpip *peer );
|
||||||
extern void udp_connect_promisc ( struct udp_connection *conn );
|
|
||||||
extern int udp_open ( struct udp_connection *conn, uint16_t local_port );
|
extern int udp_open ( struct udp_connection *conn, uint16_t local_port );
|
||||||
extern void udp_close ( struct udp_connection *conn );
|
extern void udp_close ( struct udp_connection *conn );
|
||||||
|
|
||||||
|
|||||||
@@ -52,12 +52,13 @@ udp_to_pxe ( struct udp_connection *conn ) {
|
|||||||
* @v conn UDP connection
|
* @v conn UDP connection
|
||||||
* @v data Temporary data buffer
|
* @v data Temporary data buffer
|
||||||
* @v len Size of temporary data buffer
|
* @v len Size of temporary data buffer
|
||||||
|
* @ret rc Return status code
|
||||||
*
|
*
|
||||||
* Sends the packet belonging to the current pxenv_udp_write()
|
* Sends the packet belonging to the current pxenv_udp_write()
|
||||||
* operation.
|
* operation.
|
||||||
*/
|
*/
|
||||||
static void pxe_udp_senddata ( struct udp_connection *conn, void *data,
|
static int pxe_udp_senddata ( struct udp_connection *conn, void *data,
|
||||||
size_t len ) {
|
size_t len ) {
|
||||||
struct pxe_udp_connection *pxe_udp = udp_to_pxe ( conn );
|
struct pxe_udp_connection *pxe_udp = udp_to_pxe ( conn );
|
||||||
struct s_PXENV_UDP_WRITE *pxenv_udp_write = pxe_udp->pxenv_udp_write;
|
struct s_PXENV_UDP_WRITE *pxenv_udp_write = pxe_udp->pxenv_udp_write;
|
||||||
userptr_t buffer;
|
userptr_t buffer;
|
||||||
@@ -68,7 +69,7 @@ static void pxe_udp_senddata ( struct udp_connection *conn, void *data,
|
|||||||
if ( len > pxenv_udp_write->buffer_size )
|
if ( len > pxenv_udp_write->buffer_size )
|
||||||
len = pxenv_udp_write->buffer_size;
|
len = pxenv_udp_write->buffer_size;
|
||||||
copy_from_user ( data, buffer, 0, len );
|
copy_from_user ( data, buffer, 0, len );
|
||||||
udp_send ( conn, data, len );
|
return udp_send ( conn, data, len );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -66,18 +66,6 @@ void udp_connect ( struct udp_connection *conn, struct sockaddr_tcpip *peer ) {
|
|||||||
memcpy ( &conn->peer, peer, sizeof ( conn->peer ) );
|
memcpy ( &conn->peer, peer, sizeof ( conn->peer ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Connect UDP connection to all remote hosts and ports
|
|
||||||
*
|
|
||||||
* @v conn UDP connection
|
|
||||||
*
|
|
||||||
* This undoes the effect of a call to udp_connect(), i.e. allows the
|
|
||||||
* connection to receive packets from all remote hosts and ports.
|
|
||||||
*/
|
|
||||||
void udp_connect_promisc ( struct udp_connection *conn ) {
|
|
||||||
memset ( &conn->peer, 0, sizeof ( conn->peer ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a local port
|
* Open a local port
|
||||||
*
|
*
|
||||||
@@ -140,9 +128,8 @@ int udp_senddata ( struct udp_connection *conn ) {
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
pkb_reserve ( conn->tx_pkb, UDP_MAX_HLEN );
|
pkb_reserve ( conn->tx_pkb, UDP_MAX_HLEN );
|
||||||
conn->udp_op->senddata ( conn, conn->tx_pkb->data,
|
return conn->udp_op->senddata ( conn, conn->tx_pkb->data,
|
||||||
pkb_available ( conn->tx_pkb ) );
|
pkb_available ( conn->tx_pkb ) );
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -271,14 +258,6 @@ static int udp_rx ( struct pk_buff *pkb, struct sockaddr_tcpip *st_src,
|
|||||||
/* Bound to local port and local port doesn't match */
|
/* Bound to local port and local port doesn't match */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( conn->peer.st_family &&
|
|
||||||
( memcmp ( &conn->peer, st_src,
|
|
||||||
sizeof ( conn->peer ) ) != 0 ) ) {
|
|
||||||
/* Connected to remote port and remote port
|
|
||||||
* doesn't match
|
|
||||||
*/
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Strip off the UDP header */
|
/* Strip off the UDP header */
|
||||||
pkb_pull ( pkb, sizeof ( *udphdr ) );
|
pkb_pull ( pkb, sizeof ( *udphdr ) );
|
||||||
|
|||||||
@@ -508,9 +508,10 @@ static union {
|
|||||||
* @v conn UDP connection
|
* @v conn UDP connection
|
||||||
* @v buf Temporary data buffer
|
* @v buf Temporary data buffer
|
||||||
* @v len Length of temporary data buffer
|
* @v len Length of temporary data buffer
|
||||||
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
static void dhcp_senddata ( struct udp_connection *conn,
|
static int dhcp_senddata ( struct udp_connection *conn,
|
||||||
void *buf, size_t len ) {
|
void *buf, size_t len ) {
|
||||||
struct dhcp_session *dhcp = udp_to_dhcp ( conn );
|
struct dhcp_session *dhcp = udp_to_dhcp ( conn );
|
||||||
struct dhcp_packet dhcppkt;
|
struct dhcp_packet dhcppkt;
|
||||||
int rc;
|
int rc;
|
||||||
@@ -524,14 +525,14 @@ static void dhcp_senddata ( struct udp_connection *conn,
|
|||||||
if ( ( rc = create_dhcp_packet ( dhcp, dhcp->state, buf, len,
|
if ( ( rc = create_dhcp_packet ( dhcp, dhcp->state, buf, len,
|
||||||
&dhcppkt ) ) != 0 ) {
|
&dhcppkt ) ) != 0 ) {
|
||||||
DBG ( "Could not create DHCP packet\n" );
|
DBG ( "Could not create DHCP packet\n" );
|
||||||
return;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy in options common to all requests */
|
/* Copy in options common to all requests */
|
||||||
if ( ( rc = copy_dhcp_packet_options ( &dhcppkt,
|
if ( ( rc = copy_dhcp_packet_options ( &dhcppkt,
|
||||||
&dhcp_request_options ) ) != 0){
|
&dhcp_request_options ) ) != 0){
|
||||||
DBG ( "Could not set common DHCP options\n" );
|
DBG ( "Could not set common DHCP options\n" );
|
||||||
return;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy any required options from previous server repsonse */
|
/* Copy any required options from previous server repsonse */
|
||||||
@@ -540,13 +541,13 @@ static void dhcp_senddata ( struct udp_connection *conn,
|
|||||||
DHCP_SERVER_IDENTIFIER,
|
DHCP_SERVER_IDENTIFIER,
|
||||||
DHCP_SERVER_IDENTIFIER ) ) != 0 ) {
|
DHCP_SERVER_IDENTIFIER ) ) != 0 ) {
|
||||||
DBG ( "Could not set server identifier option\n" );
|
DBG ( "Could not set server identifier option\n" );
|
||||||
return;
|
return rc;
|
||||||
}
|
}
|
||||||
if ( ( rc = copy_dhcp_packet_option ( &dhcppkt, dhcp->options,
|
if ( ( rc = copy_dhcp_packet_option ( &dhcppkt, dhcp->options,
|
||||||
DHCP_EB_YIADDR,
|
DHCP_EB_YIADDR,
|
||||||
DHCP_REQUESTED_ADDRESS ) ) != 0 ) {
|
DHCP_REQUESTED_ADDRESS ) ) != 0 ) {
|
||||||
DBG ( "Could not set requested address option\n" );
|
DBG ( "Could not set requested address option\n" );
|
||||||
return;
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -554,8 +555,10 @@ static void dhcp_senddata ( struct udp_connection *conn,
|
|||||||
if ( ( rc = udp_sendto ( conn, &sa_dhcp_server.st,
|
if ( ( rc = udp_sendto ( conn, &sa_dhcp_server.st,
|
||||||
dhcppkt.dhcphdr, dhcppkt.len ) ) != 0 ) {
|
dhcppkt.dhcphdr, dhcppkt.len ) ) != 0 ) {
|
||||||
DBG ( "Could not transmit UDP packet\n" );
|
DBG ( "Could not transmit UDP packet\n" );
|
||||||
return;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user