diff options
| author | Michael Brown | 2013-08-06 16:56:54 +0200 |
|---|---|---|
| committer | Michael Brown | 2013-08-06 16:56:54 +0200 |
| commit | 252d28f098bfd12df59fe147d7e8354be61a6da8 (patch) | |
| tree | 234bc573f3c7a27730d04016c809dc6ae5ba8c24 /src/include/ipxe | |
| parent | [ipv6] Rename sin_{family,port} to sin6_{family,port} in struct sockaddr_in6 (diff) | |
| download | ipxe-252d28f098bfd12df59fe147d7e8354be61a6da8.tar.gz ipxe-252d28f098bfd12df59fe147d7e8354be61a6da8.tar.xz ipxe-252d28f098bfd12df59fe147d7e8354be61a6da8.zip | |
[tcpip] Allow binding to unspecified privileged ports (below 1024)
Originally-implemented-by: Marin Hannache <git@mareo.fr>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe')
| -rw-r--r-- | src/include/ipxe/in.h | 30 | ||||
| -rw-r--r-- | src/include/ipxe/tcpip.h | 18 |
2 files changed, 41 insertions, 7 deletions
diff --git a/src/include/ipxe/in.h b/src/include/ipxe/in.h index 1208ae38a..eee9159fb 100644 --- a/src/include/ipxe/in.h +++ b/src/include/ipxe/in.h @@ -59,19 +59,22 @@ struct sockaddr_in { * Always set to @c AF_INET for IPv4 addresses */ sa_family_t sin_family; + /** Flags (part of struct @c sockaddr_tcpip) */ + uint16_t sin_flags; /** TCP/IP port (part of struct @c sockaddr_tcpip) */ uint16_t sin_port; /** IPv4 address */ struct in_addr sin_addr; /** Padding * - * This ensures that a struct @c sockaddr_tcpip is large - * enough to hold a socket address for any TCP/IP address - * family. + * This ensures that a struct @c sockaddr_in is large enough + * to hold a socket address for any TCP/IP address family. */ - char pad[ sizeof ( struct sockaddr ) - sizeof ( sa_family_t ) - - sizeof ( uint16_t ) - - sizeof ( struct in_addr ) ]; + char pad[ sizeof ( struct sockaddr ) - + ( sizeof ( sa_family_t ) /* sin_family */ + + sizeof ( uint16_t ) /* sin_flags */ + + sizeof ( uint16_t ) /* sin_port */ + + sizeof ( struct in_addr ) /* sin_addr */ ) ]; } __attribute__ (( may_alias )); /** @@ -83,11 +86,26 @@ struct sockaddr_in6 { * Always set to @c AF_INET6 for IPv6 addresses */ sa_family_t sin6_family; + /** Flags (part of struct @c sockaddr_tcpip) */ + uint16_t sin6_flags; /** TCP/IP port (part of struct @c sockaddr_tcpip) */ uint16_t sin6_port; uint32_t sin6_flowinfo; /* Flow number */ struct in6_addr sin6_addr; /* 128-bit destination address */ uint32_t sin6_scope_id; /* Scope ID */ + /** Padding + * + * This ensures that a struct @c sockaddr_in6 is large + * enough to hold a socket address for any TCP/IP address + * family. + */ + char pad[ sizeof ( struct sockaddr ) - + ( sizeof ( sa_family_t ) /* sin6_family */ + + sizeof ( uint16_t ) /* sin6_flags */ + + sizeof ( uint16_t ) /* sin6_port */ + + sizeof ( uint32_t ) /* sin6_flowinfo */ + + sizeof ( struct in6_addr ) /* sin6_addr */ + + sizeof ( uint32_t ) /* sin6_scope_id */ ) ]; } __attribute__ (( may_alias )); extern int inet_aton ( const char *cp, struct in_addr *inp ); diff --git a/src/include/ipxe/tcpip.h b/src/include/ipxe/tcpip.h index 34d7f88f4..0cc688a92 100644 --- a/src/include/ipxe/tcpip.h +++ b/src/include/ipxe/tcpip.h @@ -24,6 +24,16 @@ struct net_device; */ #define TCPIP_EMPTY_CSUM 0xffff +/** TCP/IP address flags */ +enum tcpip_st_flags { + /** Bind to a privileged port (less than 1024) + * + * This value is chosen as 1024 to optimise the calculations + * in tcpip_bind(). + */ + TCPIP_BIND_PRIVILEGED = 0x0400, +}; + /** * TCP/IP socket address * @@ -33,6 +43,8 @@ struct net_device; struct sockaddr_tcpip { /** Socket address family (part of struct @c sockaddr) */ sa_family_t st_family; + /** Flags */ + uint16_t st_flags; /** TCP/IP port */ uint16_t st_port; /** Padding @@ -42,7 +54,9 @@ struct sockaddr_tcpip { * family. */ char pad[ sizeof ( struct sockaddr ) - - ( sizeof ( sa_family_t ) + sizeof ( uint16_t ) ) ]; + ( sizeof ( sa_family_t ) /* st_family */ + + sizeof ( uint16_t ) /* st_flags */ + + sizeof ( uint16_t ) /* st_port */ ) ]; } __attribute__ (( may_alias )); /** @@ -125,6 +139,8 @@ extern int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip, extern uint16_t generic_tcpip_continue_chksum ( uint16_t partial, const void *data, size_t len ); extern uint16_t tcpip_chksum ( const void *data, size_t len ); +extern int tcpip_bind ( struct sockaddr_tcpip *st_local, + int ( * available ) ( int port ) ); /* Use generic_tcpip_continue_chksum() if no architecture-specific * version is available |
