net/ip: Let's make public the 2 utility unions for ip/proto headers

Though these are currently used by the core only, it will be then used
by net_context as well. This one of the steps to get rid of net_pkt's
appdata/appdatalen attributes.

Also normalizing all ip/proto parameters name to ip_hdr and proto_hdr.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2019-01-30 10:07:10 +01:00 committed by Jukka Rissanen
commit e4ebe486b8
12 changed files with 86 additions and 75 deletions

View file

@ -312,6 +312,20 @@ struct net_tcp_hdr {
u8_t optdata[0];
} __packed;
/**
* This 2 unions are here temporarly, as long as net_context.h will
* be still public and not part of the core only.
*/
union net_ip_header {
struct net_ipv4_hdr *ipv4;
struct net_ipv6_hdr *ipv6;
};
union net_proto_header {
struct net_udp_hdr *udp;
struct net_tcp_hdr *tcp;
};
#define NET_UDPH_LEN 8 /* Size of UDP header */
#define NET_TCPH_LEN 20 /* Size of TCP header */
#define NET_ICMPH_LEN 4 /* Size of ICMP header */

View file

@ -205,7 +205,7 @@ static s32_t check_hash(enum net_ip_protocol proto,
}
static inline s32_t get_conn(struct net_pkt *pkt,
union ip_header *hdr,
union net_ip_header *ip_hdr,
enum net_ip_protocol proto,
u16_t src_port,
u16_t dst_port,
@ -213,13 +213,13 @@ static inline s32_t get_conn(struct net_pkt *pkt,
{
if (IS_ENABLED(CONFIG_NET_IPV4) && net_pkt_family(pkt) == AF_INET) {
return check_hash(proto, net_pkt_family(pkt),
&hdr->ipv4->src, &hdr->ipv4->dst,
&ip_hdr->ipv4->src, &ip_hdr->ipv4->dst,
src_port, dst_port, cache_value);
}
if (IS_ENABLED(CONFIG_NET_IPV6) && net_pkt_family(pkt) == AF_INET6) {
return check_hash(proto, net_pkt_family(pkt),
&hdr->ipv6->src, &hdr->ipv6->dst,
&ip_hdr->ipv6->src, &ip_hdr->ipv6->dst,
src_port, dst_port, cache_value);
}
@ -268,15 +268,15 @@ static void cache_clear(void)
}
static inline enum net_verdict cache_check(struct net_pkt *pkt,
union ip_header *hdr,
union proto_header *proto_hdr,
union net_ip_header *ip_hdr,
union net_proto_header *proto_hdr,
enum net_ip_protocol proto,
u16_t src_port,
u16_t dst_port,
u32_t *cache_value,
s32_t *pos)
{
*pos = get_conn(pkt, hdr, proto, src_port, dst_port, cache_value);
*pos = get_conn(pkt, ip_hdr, proto, src_port, dst_port, cache_value);
if (*pos >= 0) {
if (conn_cache[*pos].idx >= 0) {
/* Connection is in the cache */
@ -290,7 +290,7 @@ static inline enum net_verdict cache_check(struct net_pkt *pkt,
conn_cache[*pos].value);
return conn->cb(conn, pkt,
hdr, proto_hdr, conn->user_data);
ip_hdr, proto_hdr, conn->user_data);
}
} else if (*cache_value > 0) {
if (cache_check_neg(*cache_value)) {
@ -685,7 +685,7 @@ int net_conn_register(enum net_ip_protocol proto,
}
static bool check_addr(struct net_pkt *pkt,
union ip_header *hdr,
union net_ip_header *ip_hdr,
struct sockaddr *addr,
bool is_remote)
{
@ -698,9 +698,9 @@ static bool check_addr(struct net_pkt *pkt,
struct in6_addr *addr6;
if (is_remote) {
addr6 = &hdr->ipv6->src;
addr6 = &ip_hdr->ipv6->src;
} else {
addr6 = &hdr->ipv6->dst;
addr6 = &ip_hdr->ipv6->dst;
}
if (!net_ipv6_is_addr_unspecified(
@ -720,9 +720,9 @@ static bool check_addr(struct net_pkt *pkt,
struct in_addr *addr4;
if (is_remote) {
addr4 = &hdr->ipv4->src;
addr4 = &ip_hdr->ipv4->src;
} else {
addr4 = &hdr->ipv4->dst;
addr4 = &ip_hdr->ipv4->dst;
}
if (net_sin(addr)->sin_addr.s_addr) {
@ -755,7 +755,7 @@ static inline void send_icmp_error(struct net_pkt *pkt)
}
static bool is_invalid_packet(struct net_pkt *pkt,
union ip_header *hdr,
union net_ip_header *ip_hdr,
u16_t src_port,
u16_t dst_port)
{
@ -764,15 +764,15 @@ static bool is_invalid_packet(struct net_pkt *pkt,
}
if (IS_ENABLED(CONFIG_NET_IPV4) && net_pkt_family(pkt) == AF_INET) {
if (net_ipv4_addr_cmp(&hdr->ipv4->src, &hdr->ipv4->dst) ||
net_ipv4_is_my_addr(&hdr->ipv4->src)) {
if (net_ipv4_addr_cmp(&ip_hdr->ipv4->src, &ip_hdr->ipv4->dst) ||
net_ipv4_is_my_addr(&ip_hdr->ipv4->src)) {
return true;
}
}
if (IS_ENABLED(CONFIG_NET_IPV6) && net_pkt_family(pkt) == AF_INET6) {
if (net_ipv6_addr_cmp(&hdr->ipv6->src, &hdr->ipv6->dst) ||
net_ipv6_is_my_addr(&hdr->ipv6->src)) {
if (net_ipv6_addr_cmp(&ip_hdr->ipv6->src, &ip_hdr->ipv6->dst) ||
net_ipv6_is_my_addr(&ip_hdr->ipv6->src)) {
return true;
}
}
@ -780,8 +780,10 @@ static bool is_invalid_packet(struct net_pkt *pkt,
return true;
}
enum net_verdict net_conn_input(struct net_pkt *pkt, union ip_header *ip_hdr,
u8_t proto, union proto_header *proto_hdr)
enum net_verdict net_conn_input(struct net_pkt *pkt,
union net_ip_header *ip_hdr,
u8_t proto,
union net_proto_header *proto_hdr)
{
struct net_if *pkt_iface = net_pkt_iface(pkt);
int i, best_match = -1;

View file

@ -29,16 +29,6 @@ struct net_conn;
struct net_conn_handle;
union ip_header {
struct net_ipv4_hdr *ipv4;
struct net_ipv6_hdr *ipv6;
};
union proto_header {
struct net_udp_hdr *udp;
struct net_tcp_hdr *tcp;
};
/**
* @brief Function that is called by connection subsystem when UDP/TCP
* packet is received and which matches local and remote IP address
@ -46,8 +36,8 @@ union proto_header {
*/
typedef enum net_verdict (*net_conn_cb_t)(struct net_conn *conn,
struct net_pkt *pkt,
union ip_header *ip_hdr,
union proto_header *proto_hdr,
union net_ip_header *ip_hdr,
union net_proto_header *proto_hdr,
void *user_data);
/**
@ -145,12 +135,15 @@ int net_conn_change_callback(struct net_conn_handle *handle,
* disabled, the function will always return NET_DROP.
*/
#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP)
enum net_verdict net_conn_input(struct net_pkt *pkt, union ip_header *ip_hdr,
u8_t proto, union proto_header *proto_hdr);
enum net_verdict net_conn_input(struct net_pkt *pkt,
union net_ip_header *ip_hdr,
u8_t proto,
union net_proto_header *proto_hdr);
#else
static inline enum net_verdict net_conn_input(struct net_pkt *pkt,
union ip_header *hdr, u8_t proto,
union proto_header *proto_hdr)
union net_ip_header *ip_hdr,
u8_t proto,
union net_proto_header *proto_hdr)
{
return NET_DROP;
}

View file

@ -875,8 +875,8 @@ static void dhcpv4_handle_reply(struct net_if *iface,
static enum net_verdict net_dhcpv4_input(struct net_conn *conn,
struct net_pkt *pkt,
union ip_header *ip_hdr,
union proto_header *proto_hdr,
union net_ip_header *ip_hdr,
union net_proto_header *proto_hdr,
void *user_data)
{
NET_PKT_DATA_ACCESS_DEFINE(dhcp_access, struct dhcp_msg);

View file

@ -192,9 +192,9 @@ enum net_verdict net_ipv4_input(struct net_pkt *pkt)
NET_PKT_DATA_ACCESS_DEFINE(tcp_access, struct net_tcp_hdr);
int real_len = net_pkt_get_len(pkt);
enum net_verdict verdict = NET_DROP;
union proto_header proto_hdr;
union net_proto_header proto_hdr;
struct net_ipv4_hdr *hdr;
union ip_header ip;
union net_ip_header ip;
int pkt_len;
net_stats_update_ipv4_recv(net_pkt_iface(pkt));

View file

@ -441,9 +441,9 @@ enum net_verdict net_ipv6_input(struct net_pkt *pkt, bool is_loopback)
u8_t ext_bitmap = 0U;
u16_t ext_len = 0U;
u8_t nexthdr, next_nexthdr;
union proto_header proto_hdr;
union net_proto_header proto_hdr;
struct net_ipv6_hdr *hdr;
union ip_header ip;
union net_ip_header ip;
int pkt_len;
net_stats_update_ipv6_recv(net_pkt_iface(pkt));

View file

@ -1478,8 +1478,8 @@ int net_context_sendto_new(struct net_context *context,
enum net_verdict net_context_packet_received(struct net_conn *conn,
struct net_pkt *pkt,
union ip_header *ip_hdr,
union proto_header *proto_hdr,
union net_ip_header *ip_hdr,
union net_proto_header *proto_hdr,
void *user_data)
{
struct net_context *context = find_context(conn);

View file

@ -147,8 +147,8 @@ void net_pkt_set_appdata_values(struct net_pkt *pkt,
enum net_verdict net_context_packet_received(struct net_conn *conn,
struct net_pkt *pkt,
union ip_header *ip_hdr,
union proto_header *proto_hdr,
union net_ip_header *ip_hdr,
union net_proto_header *proto_hdr,
void *user_data);
#if defined(CONFIG_NET_IPV4)

View file

@ -72,13 +72,13 @@ static struct tcp_backlog_entry {
#define NET_CONN_CB(name) \
static enum net_verdict _##name(struct net_conn *conn, \
struct net_pkt *pkt, \
union ip_header *ip_hdr, \
union proto_header *proto_hdr, \
union net_ip_header *ip_hdr, \
union net_proto_header *proto_hdr, \
void *user_data); \
static enum net_verdict name(struct net_conn *conn, \
struct net_pkt *pkt, \
union ip_header *ip_hdr, \
union proto_header *proto_hdr, \
union net_ip_header *ip_hdr, \
union net_proto_header *proto_hdr, \
void *user_data) \
{ \
enum net_verdict result; \
@ -91,8 +91,8 @@ static struct tcp_backlog_entry {
} \
static enum net_verdict _##name(struct net_conn *conn, \
struct net_pkt *pkt, \
union ip_header *ip_hdr, \
union proto_header *proto_hdr, \
union net_ip_header *ip_hdr, \
union net_proto_header *proto_hdr, \
void *user_data) \
@ -1581,7 +1581,7 @@ static void backlog_ack_timeout(struct k_work *work)
}
static void tcp_copy_ip_addr_from_hdr(sa_family_t family,
union ip_header *ip_hdr,
union net_ip_header *ip_hdr,
struct net_tcp_hdr *tcp_hdr,
struct sockaddr *addr,
bool is_src_addr)
@ -1622,7 +1622,7 @@ static void tcp_copy_ip_addr_from_hdr(sa_family_t family,
}
static int tcp_backlog_find(struct net_pkt *pkt,
union ip_header *hdr,
union net_ip_header *ip_hdr,
struct net_tcp_hdr *tcp_hdr,
int *empty_slot)
{
@ -1646,7 +1646,8 @@ static int tcp_backlog_find(struct net_pkt *pkt,
}
if (memcmp(&net_sin(&tcp_backlog[i].remote)->sin_addr,
&hdr->ipv4->src, sizeof(struct in_addr))) {
&ip_hdr->ipv4->src,
sizeof(struct in_addr))) {
continue;
}
} else if (IS_ENABLED(CONFIG_NET_IPV6) &&
@ -1657,7 +1658,8 @@ static int tcp_backlog_find(struct net_pkt *pkt,
}
if (memcmp(&net_sin6(&tcp_backlog[i].remote)->sin6_addr,
&hdr->ipv6->src, sizeof(struct in6_addr))) {
&ip_hdr->ipv6->src,
sizeof(struct in6_addr))) {
continue;
}
}
@ -1673,7 +1675,7 @@ static int tcp_backlog_find(struct net_pkt *pkt,
}
static int tcp_backlog_syn(struct net_pkt *pkt,
union ip_header *ip_hdr,
union net_ip_header *ip_hdr,
struct net_tcp_hdr *tcp_hdr,
struct net_context *context,
u16_t send_mss)
@ -1705,7 +1707,7 @@ static int tcp_backlog_syn(struct net_pkt *pkt,
}
static int tcp_backlog_ack(struct net_pkt *pkt,
union ip_header *ip_hdr,
union net_ip_header *ip_hdr,
struct net_tcp_hdr *tcp_hdr,
struct net_context *context)
{
@ -1734,7 +1736,7 @@ static int tcp_backlog_ack(struct net_pkt *pkt,
}
static int tcp_backlog_rst(struct net_pkt *pkt,
union ip_header *ip_hdr,
union net_ip_header *ip_hdr,
struct net_tcp_hdr *tcp_hdr)
{
int r;
@ -2010,8 +2012,8 @@ static int send_reset(struct net_context *context,
*
* Prototype:
* enum net_verdict tcp_established(struct net_conn *conn,
* union ip_header *ip_hdr,
* union data_header *proto_hdr,
* union net_ip_header *ip_hdr,
* union net_proto_header *proto_hdr,
* struct net_pkt *pkt,
* void *user_data)
*/
@ -2204,8 +2206,8 @@ unlock:
* Prototype:
* enum net_verdict tcp_synack_received(struct net_conn *conn,
* struct net_pkt *pkt,
* union ip_header *ip_hdr,
* union data_header *proto_hdr,
* union net_ip_header *ip_hdr,
* union net_proto_header *proto_hdr,
* void *user_data)
*/
NET_CONN_CB(tcp_synack_received)
@ -2298,7 +2300,7 @@ NET_CONN_CB(tcp_synack_received)
return NET_DROP;
}
static void get_sockaddr_ptr(union ip_header *ip_hdr,
static void get_sockaddr_ptr(union net_ip_header *ip_hdr,
struct net_tcp_hdr *tcp_hdr,
sa_family_t family,
struct sockaddr_ptr *addr)
@ -2341,8 +2343,8 @@ static inline void copy_pool_vars(struct net_context *new_context,
* Prototype:
* enum net_verdict tcp_syn_rcvd(struct net_conn *conn,
* struct net_pkt *pkt,
* union ip_header *ip_hdr,
* union data_header *proto_hdr,
* union net_ip_header *ip_hdr,
* union net_proto_header *proto_hdr,
* void *user_data)
*/
NET_CONN_CB(tcp_syn_rcvd)

View file

@ -1125,8 +1125,8 @@ static void add_nbr(struct net_if *iface,
static enum net_verdict udp_data_received(struct net_conn *conn,
struct net_pkt *pkt,
union ip_header *ip_hdr,
union proto_header *proto_hdr,
union net_ip_header *ip_hdr,
union net_proto_header *proto_hdr,
void *user_data)
{
DBG("Data %p received\n", pkt);

View file

@ -229,8 +229,8 @@ static struct ud *returned_ud;
static enum net_verdict test_ok(struct net_conn *conn,
struct net_pkt *pkt,
union ip_header *ip_hdr,
union proto_header *proto_hdr,
union net_ip_header *ip_hdr,
union net_proto_header *proto_hdr,
void *user_data)
{
struct ud *ud = (struct ud *)user_data;
@ -256,8 +256,8 @@ static enum net_verdict test_ok(struct net_conn *conn,
static enum net_verdict test_fail(struct net_conn *conn,
struct net_pkt *pkt,
union ip_header *ip_hdr,
union proto_header *proto_hdr,
union net_ip_header *ip_hdr,
union net_proto_header *proto_hdr,
void *user_data)
{
/* This function should never be called as there should not

View file

@ -151,8 +151,8 @@ static struct ud *returned_ud;
static enum net_verdict test_ok(struct net_conn *conn,
struct net_pkt *pkt,
union ip_header *ip_hdr,
union proto_header *proto_hdr,
union net_ip_header *ip_hdr,
union net_proto_header *proto_hdr,
void *user_data)
{
struct ud *ud = (struct ud *)user_data;
@ -178,8 +178,8 @@ static enum net_verdict test_ok(struct net_conn *conn,
static enum net_verdict test_fail(struct net_conn *conn,
struct net_pkt *pkt,
union ip_header *ip_hdr,
union proto_header *proto_hdr,
union net_ip_header *ip_hdr,
union net_proto_header *proto_hdr,
void *user_data)
{
/* This function should never be called as there should not