New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Network raw socket support #11229
Network raw socket support #11229
Conversation
Add ETH_P_xxx protocol types if they are missing. After this we can use the protocol types when working with BSD sockets. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Various defines and helpers for supporting raw sockets. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
These are used by the network device driver and net_core when receiving the network packet. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit adds basic raw socket support to net_context and allows application to receive or send network packets in raw format. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
We need to store the used upper layer protocol information into the network packet so that the packet can be handled if raw socket support is enabled. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Print information about raw network packets received. Do not send them back in this version. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Codecov Report
@@ Coverage Diff @@
## master #11229 +/- ##
=========================================
- Coverage 53.1% 53.01% -0.1%
=========================================
Files 218 218
Lines 26883 26926 +43
Branches 5952 5963 +11
=========================================
- Hits 14277 14275 -2
- Misses 10172 10209 +37
- Partials 2434 2442 +8
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR says "sockets", but at its current state, it doens't have changes for anything in net/lib/sockets/ (that's mentioned in the current description, yeah).
Raw sockets is very peculiar matter. Recv/send sides are quite inconsistent regarding for lower-level protocol header they return/accept or not.
I would like to see a sample application, in the vein of existing samples/net/sockets/, which can be compiled on both Linux and Zephyr, and behaves the same on both. (That's as a replacement of properly spec'ing what this is supposed to do - as we can't see to make people first explain what they want to do, and only then start dumping code.)
NET_CONTEXT_AF_INET = 0, | ||
NET_CONTEXT_AF_INET6, | ||
NET_CONTEXT_AF_PACKET, | ||
} __packed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why __packed?
NET_CONTEXT_SOCK_DGRAM = 0, | ||
NET_CONTEXT_SOCK_STREAM, | ||
NET_CONTEXT_SOCK_RAW, | ||
} __packed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
} | ||
|
||
return AF_INET; | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall it return AF_UNSPEC here instead?
@@ -0,0 +1,164 @@ | |||
/** @file | |||
* @brief Generic raw socket connection related functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gruik. I really hope you are going to merge all in connection.c instead of c/p 95% of its bare logic here just to add small raw dedicated stuff.
@@ -212,9 +237,11 @@ int net_context_get(sa_family_t family, | |||
net_context_set_type(&contexts[i], type); | |||
net_context_set_ip_proto(&contexts[i], ip_proto); | |||
|
|||
#if defined(CONFIG_NET_IPV4) || defined(CONFIG_NET_IPV6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use IS_ENABLED()
@@ -997,6 +1097,28 @@ static int sendto(struct net_pkt *pkt, | |||
} | |||
} else | |||
#endif /* CONFIG_NET_IPV4 */ | |||
|
|||
#if defined(CONFIG_NET_SOCKET_RAW) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IS_ENABLED
@@ -149,6 +149,17 @@ struct net_stats_udp { | |||
net_stats_t chkerr; | |||
}; | |||
|
|||
struct net_stats_raw { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the stats related part into its own patch
@@ -178,6 +178,12 @@ struct net_pkt { | |||
u8_t ieee802154_rssi; /* Received Signal Strength Indication */ | |||
u8_t ieee802154_lqi; /* Link Quality Indicator */ | |||
#endif | |||
|
|||
#if defined(CONFIG_NET_SOCKET_RAW) | |||
u16_t l2_proto; /* IEEE 802.3 protocol value of the L2 (in network |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put it in a union, I guess above 116 to 140 could be the right place: there are 2 u8_t, which would need to be combined in an anonymous struct, and that u16_t. something like that
Also, can you call it raw_proto instead?
@@ -321,6 +322,8 @@ static int read_data(struct eth_context *ctx, int fd) | |||
count += frag->len; | |||
} while (ret > 0); | |||
|
|||
type = NET_ETH_HDR(pkt)->type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's something we'll need to think about. It piles up more stuff to add in every driver, while it could be centralized. I still would like to see this put into ethernet l2 somehow, here at this point you don't know if the packet is meant for a raw socket or not (and this approach would also make the union stuff as seen in previous patch impossible).
@@ -283,11 +298,14 @@ struct net_context { | |||
#endif | |||
} options; | |||
|
|||
/** Network interface assigned to this context */ | |||
u8_t iface; | |||
/** Protocol (UDP, TCP or IEEE 802.3 protocol value */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing ')'
This is work-in-progress PR, it is by no means ready but is more in RFC state atm.
Things that are still missing: