net/ethernet: Centralize where and when header is filled in

Current code generating Ethernet header is scattered all over the place,
sometimes in functions that are supposed to check something (and not
filling the header). Not to say about innefficiency.

Src ll address does not need to be set in L2 as net_if.c handles that
already.

Broadcast dst ll address is the same in ipv4 or ipv6, thus factorizing.
In each case, multicast is filled in only at the relevant place.

This is the first step towards changing L2 sending logic, when L2 send
API function will be the only point of sending. The redirection from
driver to L2 again (which finally uses the right device API function to
send) it a temporary hack.

This simplifies the code but will also enable using statically
allocated net_buf and ethernet header payload buffer afterwards.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2018-06-25 10:22:54 +02:00 committed by Anas Nashif
commit dcc6eddfef
4 changed files with 176 additions and 197 deletions

View file

@ -218,6 +218,9 @@ struct ethernet_api {
/** Return ptp_clock device that is tied to this ethernet device */
struct device *(*get_ptp_clock)(struct device *dev);
#endif /* CONFIG_PTP_CLOCK */
/** Send a network packet */
int (*send)(struct device *dev, struct net_pkt *pkt);
};
struct net_eth_hdr {
@ -535,23 +538,7 @@ static inline bool net_eth_get_vlan_status(struct net_if *iface)
}
#endif /* CONFIG_NET_VLAN */
/**
* @brief Fill ethernet header in network packet.
*
* @param ctx Ethernet context
* @param pkt Network packet
* @param ptype Upper level protocol type (in network byte order)
* @param src Source ethernet address
* @param dst Destination ethernet address
*
* @return Pointer to newly inserted net_buf where header is found,
* NULL otherwise.
*/
struct net_buf *net_eth_fill_header(struct ethernet_context *ctx,
struct net_pkt *pkt,
u32_t ptype,
u8_t *src,
u8_t *dst);
int net_eth_send(struct net_if *iface, struct net_pkt *pkt);
/**
* @brief Inform ethernet L2 driver that ethernet carrier is detected.