I’m trying to write a simple network bridge module, got the following rx handler:
static rx_handler_result_t handle_frame(struct sk_buff **pskb) {
struct sk_buff *skb = *pskb;
struct sk_buff *cloned_skb;
// Forward packets from eth1 to eth0
if (skb->dev == dev_eth1) {
struct ethhdr *eth = eth_hdr(skb);
pr_info("Incoming packet: src MAC %pM, dst MAC %pM, ethertype 0x%04xn",
eth->h_source, eth->h_dest, ntohs(eth->h_proto));
cloned_skb = skb_clone(skb, GFP_ATOMIC);
if (!cloned_skb) {
pr_err("Failed to clone skbn");
return RX_HANDLER_PASS;
}
cloned_skb->dev = dev_eth0;
//skb_reset_mac_header(cloned_skb);
// skb_reset_network_header(cloned_skb);
// skb_reset_transport_header(cloned_skb);
eth = eth_hdr(cloned_skb);
pr_info("Sending packet on eth0: src MAC %pM, dst MAC %pM, ethertype 0x%04xn",
eth->h_source, eth->h_dest, ntohs(eth->h_proto));
dev_queue_xmit(cloned_skb);
return RX_HANDLER_CONSUMED;
}
}
Even though both printk’s are showing same contents, on the wire i see completely garbled frame (even mac addresses are random and also are incrementing, as if cloned_skb data was affecting header).
I’ve checked some of the other kernel drivers, like vlan, they seem to be using similar approach there.
Please any clues on what am i doing wrong.
user542088 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.