Skip to content

Commit e4ebe48

Browse files
Tomasz Bursztykajukkar
authored andcommitted
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 <[email protected]>
1 parent 6a5f12b commit e4ebe48

File tree

12 files changed

+86
-75
lines changed

12 files changed

+86
-75
lines changed

include/net/net_ip.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,20 @@ struct net_tcp_hdr {
312312
u8_t optdata[0];
313313
} __packed;
314314

315+
/**
316+
* This 2 unions are here temporarly, as long as net_context.h will
317+
* be still public and not part of the core only.
318+
*/
319+
union net_ip_header {
320+
struct net_ipv4_hdr *ipv4;
321+
struct net_ipv6_hdr *ipv6;
322+
};
323+
324+
union net_proto_header {
325+
struct net_udp_hdr *udp;
326+
struct net_tcp_hdr *tcp;
327+
};
328+
315329
#define NET_UDPH_LEN 8 /* Size of UDP header */
316330
#define NET_TCPH_LEN 20 /* Size of TCP header */
317331
#define NET_ICMPH_LEN 4 /* Size of ICMP header */

subsys/net/ip/connection.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -205,21 +205,21 @@ static s32_t check_hash(enum net_ip_protocol proto,
205205
}
206206

207207
static inline s32_t get_conn(struct net_pkt *pkt,
208-
union ip_header *hdr,
208+
union net_ip_header *ip_hdr,
209209
enum net_ip_protocol proto,
210210
u16_t src_port,
211211
u16_t dst_port,
212212
u32_t *cache_value)
213213
{
214214
if (IS_ENABLED(CONFIG_NET_IPV4) && net_pkt_family(pkt) == AF_INET) {
215215
return check_hash(proto, net_pkt_family(pkt),
216-
&hdr->ipv4->src, &hdr->ipv4->dst,
216+
&ip_hdr->ipv4->src, &ip_hdr->ipv4->dst,
217217
src_port, dst_port, cache_value);
218218
}
219219

220220
if (IS_ENABLED(CONFIG_NET_IPV6) && net_pkt_family(pkt) == AF_INET6) {
221221
return check_hash(proto, net_pkt_family(pkt),
222-
&hdr->ipv6->src, &hdr->ipv6->dst,
222+
&ip_hdr->ipv6->src, &ip_hdr->ipv6->dst,
223223
src_port, dst_port, cache_value);
224224
}
225225

@@ -268,15 +268,15 @@ static void cache_clear(void)
268268
}
269269

270270
static inline enum net_verdict cache_check(struct net_pkt *pkt,
271-
union ip_header *hdr,
272-
union proto_header *proto_hdr,
271+
union net_ip_header *ip_hdr,
272+
union net_proto_header *proto_hdr,
273273
enum net_ip_protocol proto,
274274
u16_t src_port,
275275
u16_t dst_port,
276276
u32_t *cache_value,
277277
s32_t *pos)
278278
{
279-
*pos = get_conn(pkt, hdr, proto, src_port, dst_port, cache_value);
279+
*pos = get_conn(pkt, ip_hdr, proto, src_port, dst_port, cache_value);
280280
if (*pos >= 0) {
281281
if (conn_cache[*pos].idx >= 0) {
282282
/* Connection is in the cache */
@@ -290,7 +290,7 @@ static inline enum net_verdict cache_check(struct net_pkt *pkt,
290290
conn_cache[*pos].value);
291291

292292
return conn->cb(conn, pkt,
293-
hdr, proto_hdr, conn->user_data);
293+
ip_hdr, proto_hdr, conn->user_data);
294294
}
295295
} else if (*cache_value > 0) {
296296
if (cache_check_neg(*cache_value)) {
@@ -685,7 +685,7 @@ int net_conn_register(enum net_ip_protocol proto,
685685
}
686686

687687
static bool check_addr(struct net_pkt *pkt,
688-
union ip_header *hdr,
688+
union net_ip_header *ip_hdr,
689689
struct sockaddr *addr,
690690
bool is_remote)
691691
{
@@ -698,9 +698,9 @@ static bool check_addr(struct net_pkt *pkt,
698698
struct in6_addr *addr6;
699699

700700
if (is_remote) {
701-
addr6 = &hdr->ipv6->src;
701+
addr6 = &ip_hdr->ipv6->src;
702702
} else {
703-
addr6 = &hdr->ipv6->dst;
703+
addr6 = &ip_hdr->ipv6->dst;
704704
}
705705

706706
if (!net_ipv6_is_addr_unspecified(
@@ -720,9 +720,9 @@ static bool check_addr(struct net_pkt *pkt,
720720
struct in_addr *addr4;
721721

722722
if (is_remote) {
723-
addr4 = &hdr->ipv4->src;
723+
addr4 = &ip_hdr->ipv4->src;
724724
} else {
725-
addr4 = &hdr->ipv4->dst;
725+
addr4 = &ip_hdr->ipv4->dst;
726726
}
727727

728728
if (net_sin(addr)->sin_addr.s_addr) {
@@ -755,7 +755,7 @@ static inline void send_icmp_error(struct net_pkt *pkt)
755755
}
756756

757757
static bool is_invalid_packet(struct net_pkt *pkt,
758-
union ip_header *hdr,
758+
union net_ip_header *ip_hdr,
759759
u16_t src_port,
760760
u16_t dst_port)
761761
{
@@ -764,24 +764,26 @@ static bool is_invalid_packet(struct net_pkt *pkt,
764764
}
765765

766766
if (IS_ENABLED(CONFIG_NET_IPV4) && net_pkt_family(pkt) == AF_INET) {
767-
if (net_ipv4_addr_cmp(&hdr->ipv4->src, &hdr->ipv4->dst) ||
768-
net_ipv4_is_my_addr(&hdr->ipv4->src)) {
767+
if (net_ipv4_addr_cmp(&ip_hdr->ipv4->src, &ip_hdr->ipv4->dst) ||
768+
net_ipv4_is_my_addr(&ip_hdr->ipv4->src)) {
769769
return true;
770770
}
771771
}
772772

773773
if (IS_ENABLED(CONFIG_NET_IPV6) && net_pkt_family(pkt) == AF_INET6) {
774-
if (net_ipv6_addr_cmp(&hdr->ipv6->src, &hdr->ipv6->dst) ||
775-
net_ipv6_is_my_addr(&hdr->ipv6->src)) {
774+
if (net_ipv6_addr_cmp(&ip_hdr->ipv6->src, &ip_hdr->ipv6->dst) ||
775+
net_ipv6_is_my_addr(&ip_hdr->ipv6->src)) {
776776
return true;
777777
}
778778
}
779779

780780
return true;
781781
}
782782

783-
enum net_verdict net_conn_input(struct net_pkt *pkt, union ip_header *ip_hdr,
784-
u8_t proto, union proto_header *proto_hdr)
783+
enum net_verdict net_conn_input(struct net_pkt *pkt,
784+
union net_ip_header *ip_hdr,
785+
u8_t proto,
786+
union net_proto_header *proto_hdr)
785787
{
786788
struct net_if *pkt_iface = net_pkt_iface(pkt);
787789
int i, best_match = -1;

subsys/net/ip/connection.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,15 @@ struct net_conn;
2929

3030
struct net_conn_handle;
3131

32-
union ip_header {
33-
struct net_ipv4_hdr *ipv4;
34-
struct net_ipv6_hdr *ipv6;
35-
};
36-
37-
union proto_header {
38-
struct net_udp_hdr *udp;
39-
struct net_tcp_hdr *tcp;
40-
};
41-
4232
/**
4333
* @brief Function that is called by connection subsystem when UDP/TCP
4434
* packet is received and which matches local and remote IP address
4535
* and port.
4636
*/
4737
typedef enum net_verdict (*net_conn_cb_t)(struct net_conn *conn,
4838
struct net_pkt *pkt,
49-
union ip_header *ip_hdr,
50-
union proto_header *proto_hdr,
39+
union net_ip_header *ip_hdr,
40+
union net_proto_header *proto_hdr,
5141
void *user_data);
5242

5343
/**
@@ -145,12 +135,15 @@ int net_conn_change_callback(struct net_conn_handle *handle,
145135
* disabled, the function will always return NET_DROP.
146136
*/
147137
#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP)
148-
enum net_verdict net_conn_input(struct net_pkt *pkt, union ip_header *ip_hdr,
149-
u8_t proto, union proto_header *proto_hdr);
138+
enum net_verdict net_conn_input(struct net_pkt *pkt,
139+
union net_ip_header *ip_hdr,
140+
u8_t proto,
141+
union net_proto_header *proto_hdr);
150142
#else
151143
static inline enum net_verdict net_conn_input(struct net_pkt *pkt,
152-
union ip_header *hdr, u8_t proto,
153-
union proto_header *proto_hdr)
144+
union net_ip_header *ip_hdr,
145+
u8_t proto,
146+
union net_proto_header *proto_hdr)
154147
{
155148
return NET_DROP;
156149
}

subsys/net/ip/dhcpv4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,8 @@ static void dhcpv4_handle_reply(struct net_if *iface,
875875

876876
static enum net_verdict net_dhcpv4_input(struct net_conn *conn,
877877
struct net_pkt *pkt,
878-
union ip_header *ip_hdr,
879-
union proto_header *proto_hdr,
878+
union net_ip_header *ip_hdr,
879+
union net_proto_header *proto_hdr,
880880
void *user_data)
881881
{
882882
NET_PKT_DATA_ACCESS_DEFINE(dhcp_access, struct dhcp_msg);

subsys/net/ip/ipv4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ enum net_verdict net_ipv4_input(struct net_pkt *pkt)
192192
NET_PKT_DATA_ACCESS_DEFINE(tcp_access, struct net_tcp_hdr);
193193
int real_len = net_pkt_get_len(pkt);
194194
enum net_verdict verdict = NET_DROP;
195-
union proto_header proto_hdr;
195+
union net_proto_header proto_hdr;
196196
struct net_ipv4_hdr *hdr;
197-
union ip_header ip;
197+
union net_ip_header ip;
198198
int pkt_len;
199199

200200
net_stats_update_ipv4_recv(net_pkt_iface(pkt));

subsys/net/ip/ipv6.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,9 @@ enum net_verdict net_ipv6_input(struct net_pkt *pkt, bool is_loopback)
441441
u8_t ext_bitmap = 0U;
442442
u16_t ext_len = 0U;
443443
u8_t nexthdr, next_nexthdr;
444-
union proto_header proto_hdr;
444+
union net_proto_header proto_hdr;
445445
struct net_ipv6_hdr *hdr;
446-
union ip_header ip;
446+
union net_ip_header ip;
447447
int pkt_len;
448448

449449
net_stats_update_ipv6_recv(net_pkt_iface(pkt));

subsys/net/ip/net_context.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,8 +1478,8 @@ int net_context_sendto_new(struct net_context *context,
14781478

14791479
enum net_verdict net_context_packet_received(struct net_conn *conn,
14801480
struct net_pkt *pkt,
1481-
union ip_header *ip_hdr,
1482-
union proto_header *proto_hdr,
1481+
union net_ip_header *ip_hdr,
1482+
union net_proto_header *proto_hdr,
14831483
void *user_data)
14841484
{
14851485
struct net_context *context = find_context(conn);

subsys/net/ip/net_private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ void net_pkt_set_appdata_values(struct net_pkt *pkt,
147147

148148
enum net_verdict net_context_packet_received(struct net_conn *conn,
149149
struct net_pkt *pkt,
150-
union ip_header *ip_hdr,
151-
union proto_header *proto_hdr,
150+
union net_ip_header *ip_hdr,
151+
union net_proto_header *proto_hdr,
152152
void *user_data);
153153

154154
#if defined(CONFIG_NET_IPV4)

subsys/net/ip/tcp.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ static struct tcp_backlog_entry {
7272
#define NET_CONN_CB(name) \
7373
static enum net_verdict _##name(struct net_conn *conn, \
7474
struct net_pkt *pkt, \
75-
union ip_header *ip_hdr, \
76-
union proto_header *proto_hdr, \
75+
union net_ip_header *ip_hdr, \
76+
union net_proto_header *proto_hdr, \
7777
void *user_data); \
7878
static enum net_verdict name(struct net_conn *conn, \
7979
struct net_pkt *pkt, \
80-
union ip_header *ip_hdr, \
81-
union proto_header *proto_hdr, \
80+
union net_ip_header *ip_hdr, \
81+
union net_proto_header *proto_hdr, \
8282
void *user_data) \
8383
{ \
8484
enum net_verdict result; \
@@ -91,8 +91,8 @@ static struct tcp_backlog_entry {
9191
} \
9292
static enum net_verdict _##name(struct net_conn *conn, \
9393
struct net_pkt *pkt, \
94-
union ip_header *ip_hdr, \
95-
union proto_header *proto_hdr, \
94+
union net_ip_header *ip_hdr, \
95+
union net_proto_header *proto_hdr, \
9696
void *user_data) \
9797

9898

@@ -1581,7 +1581,7 @@ static void backlog_ack_timeout(struct k_work *work)
15811581
}
15821582

15831583
static void tcp_copy_ip_addr_from_hdr(sa_family_t family,
1584-
union ip_header *ip_hdr,
1584+
union net_ip_header *ip_hdr,
15851585
struct net_tcp_hdr *tcp_hdr,
15861586
struct sockaddr *addr,
15871587
bool is_src_addr)
@@ -1622,7 +1622,7 @@ static void tcp_copy_ip_addr_from_hdr(sa_family_t family,
16221622
}
16231623

16241624
static int tcp_backlog_find(struct net_pkt *pkt,
1625-
union ip_header *hdr,
1625+
union net_ip_header *ip_hdr,
16261626
struct net_tcp_hdr *tcp_hdr,
16271627
int *empty_slot)
16281628
{
@@ -1646,7 +1646,8 @@ static int tcp_backlog_find(struct net_pkt *pkt,
16461646
}
16471647

16481648
if (memcmp(&net_sin(&tcp_backlog[i].remote)->sin_addr,
1649-
&hdr->ipv4->src, sizeof(struct in_addr))) {
1649+
&ip_hdr->ipv4->src,
1650+
sizeof(struct in_addr))) {
16501651
continue;
16511652
}
16521653
} else if (IS_ENABLED(CONFIG_NET_IPV6) &&
@@ -1657,7 +1658,8 @@ static int tcp_backlog_find(struct net_pkt *pkt,
16571658
}
16581659

16591660
if (memcmp(&net_sin6(&tcp_backlog[i].remote)->sin6_addr,
1660-
&hdr->ipv6->src, sizeof(struct in6_addr))) {
1661+
&ip_hdr->ipv6->src,
1662+
sizeof(struct in6_addr))) {
16611663
continue;
16621664
}
16631665
}
@@ -1673,7 +1675,7 @@ static int tcp_backlog_find(struct net_pkt *pkt,
16731675
}
16741676

16751677
static int tcp_backlog_syn(struct net_pkt *pkt,
1676-
union ip_header *ip_hdr,
1678+
union net_ip_header *ip_hdr,
16771679
struct net_tcp_hdr *tcp_hdr,
16781680
struct net_context *context,
16791681
u16_t send_mss)
@@ -1705,7 +1707,7 @@ static int tcp_backlog_syn(struct net_pkt *pkt,
17051707
}
17061708

17071709
static int tcp_backlog_ack(struct net_pkt *pkt,
1708-
union ip_header *ip_hdr,
1710+
union net_ip_header *ip_hdr,
17091711
struct net_tcp_hdr *tcp_hdr,
17101712
struct net_context *context)
17111713
{
@@ -1734,7 +1736,7 @@ static int tcp_backlog_ack(struct net_pkt *pkt,
17341736
}
17351737

17361738
static int tcp_backlog_rst(struct net_pkt *pkt,
1737-
union ip_header *ip_hdr,
1739+
union net_ip_header *ip_hdr,
17381740
struct net_tcp_hdr *tcp_hdr)
17391741
{
17401742
int r;
@@ -2010,8 +2012,8 @@ static int send_reset(struct net_context *context,
20102012
*
20112013
* Prototype:
20122014
* enum net_verdict tcp_established(struct net_conn *conn,
2013-
* union ip_header *ip_hdr,
2014-
* union data_header *proto_hdr,
2015+
* union net_ip_header *ip_hdr,
2016+
* union net_proto_header *proto_hdr,
20152017
* struct net_pkt *pkt,
20162018
* void *user_data)
20172019
*/
@@ -2204,8 +2206,8 @@ NET_CONN_CB(tcp_established)
22042206
* Prototype:
22052207
* enum net_verdict tcp_synack_received(struct net_conn *conn,
22062208
* struct net_pkt *pkt,
2207-
* union ip_header *ip_hdr,
2208-
* union data_header *proto_hdr,
2209+
* union net_ip_header *ip_hdr,
2210+
* union net_proto_header *proto_hdr,
22092211
* void *user_data)
22102212
*/
22112213
NET_CONN_CB(tcp_synack_received)
@@ -2298,7 +2300,7 @@ NET_CONN_CB(tcp_synack_received)
22982300
return NET_DROP;
22992301
}
23002302

2301-
static void get_sockaddr_ptr(union ip_header *ip_hdr,
2303+
static void get_sockaddr_ptr(union net_ip_header *ip_hdr,
23022304
struct net_tcp_hdr *tcp_hdr,
23032305
sa_family_t family,
23042306
struct sockaddr_ptr *addr)
@@ -2341,8 +2343,8 @@ static inline void copy_pool_vars(struct net_context *new_context,
23412343
* Prototype:
23422344
* enum net_verdict tcp_syn_rcvd(struct net_conn *conn,
23432345
* struct net_pkt *pkt,
2344-
* union ip_header *ip_hdr,
2345-
* union data_header *proto_hdr,
2346+
* union net_ip_header *ip_hdr,
2347+
* union net_proto_header *proto_hdr,
23462348
* void *user_data)
23472349
*/
23482350
NET_CONN_CB(tcp_syn_rcvd)

0 commit comments

Comments
 (0)