net: pkt: Add ll_proto_type field
The L2 protocol type information is not carried to the upper layers. This is problematic for packet sockets, as the address structure in recvfrom() is supposed to provide this information. Fix this by adding ll_proto_type field in the net_pkt structure. Set the protocol type in the Ethernet L2 when packet is processed. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
parent
0023ba45ee
commit
b5b5c29f2d
3 changed files with 14 additions and 0 deletions
|
@ -124,6 +124,7 @@ struct net_pkt {
|
|||
/* Filled by layer 2 when network packet is received. */
|
||||
struct net_linkaddr lladdr_src;
|
||||
struct net_linkaddr lladdr_dst;
|
||||
uint16_t ll_proto_type;
|
||||
|
||||
#if defined(CONFIG_NET_TCP)
|
||||
/** Allow placing the packet into sys_slist_t */
|
||||
|
@ -1018,6 +1019,16 @@ static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
|
|||
net_pkt_lladdr_src(pkt)->len = 0U;
|
||||
}
|
||||
|
||||
static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
|
||||
{
|
||||
return pkt->ll_proto_type;
|
||||
}
|
||||
|
||||
static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
|
||||
{
|
||||
pkt->ll_proto_type = type;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_IEEE802154) || defined(CONFIG_IEEE802154_RAW_MODE)
|
||||
static inline uint8_t net_pkt_ieee802154_rssi(struct net_pkt *pkt)
|
||||
{
|
||||
|
|
|
@ -1775,6 +1775,7 @@ static void clone_pkt_attributes(struct net_pkt *pkt, struct net_pkt *clone_pkt)
|
|||
net_pkt_set_captured(clone_pkt, net_pkt_is_captured(pkt));
|
||||
net_pkt_set_l2_bridged(clone_pkt, net_pkt_is_l2_bridged(pkt));
|
||||
net_pkt_set_l2_processed(clone_pkt, net_pkt_is_l2_processed(pkt));
|
||||
net_pkt_set_ll_proto_type(clone_pkt, net_pkt_ll_proto_type(pkt));
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_IPV4) && net_pkt_family(pkt) == AF_INET) {
|
||||
net_pkt_set_ipv4_ttl(clone_pkt, net_pkt_ipv4_ttl(pkt));
|
||||
|
|
|
@ -274,6 +274,8 @@ static enum net_verdict ethernet_recv(struct net_if *iface,
|
|||
lladdr->len = sizeof(struct net_eth_addr);
|
||||
lladdr->type = NET_LINK_ETHERNET;
|
||||
|
||||
net_pkt_set_ll_proto_type(pkt, type);
|
||||
|
||||
if (net_eth_is_vlan_enabled(ctx, iface)) {
|
||||
if (type == NET_ETH_PTYPE_VLAN ||
|
||||
(eth_is_vlan_tag_stripped(iface) &&
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue