drivers/net/wan/hdlc: Set skb->protocol before transmitting
Subsystems (3)
PATCH 1/1 drivers/net/wan/hdlc: Set skb->protocol before transmitting
This patch sets skb->protocol before transmitting frames on the HDLC device, so that a user listening on the HDLC device with an AF_PACKET socket will see outgoing frames' sll_protocol field correctly set and consistent with that of incoming frames.
1. Control frames in hdlc_cisco and hdlc_ppp
When these drivers send control frames, skb->protocol is not set.
This value should be set to htons(ETH_P_HDLC), because when receiving control frames, their skb->protocol is set to htons(ETH_P_HDLC).
When receiving, hdlc_type_trans in hdlc.h is called, which then calls cisco_type_trans or ppp_type_trans. The skb->protocol of control frames is set to htons(ETH_P_HDLC) so that the control frames can be received by hdlc_rcv in hdlc.c, which calls cisco_rx or ppp_rx to process the control frames.
2. hdlc_fr
When this driver sends control frames, skb->protocol is set to internal values used in this driver.
When this driver sends data frames (from upper stacked PVC devices), skb->protocol is the same as that of the user data packet being sent on the upper PVC device (for normal PVC devices), or is htons(ETH_P_802_3) (for Ethernet-emulating PVC devices).
However, skb->protocol for both control frames and data frames should be set to htons(ETH_P_HDLC), because when receiving, all frames received on the HDLC device will have their skb->protocol set to htons(ETH_P_HDLC).
When receiving, hdlc_type_trans in hdlc.h is called, and because this driver doesn't provide a type_trans function in struct hdlc_proto, all frames will have their skb->protocol set to htons(ETH_P_HDLC). The frames are then received by hdlc_rcv in hdlc.c, which calls fr_rx to process the frames (control frames are consumed and data frames are re-received on upper PVC devices).
--- drivers/net/wan/hdlc_cisco.c | 1 + drivers/net/wan/hdlc_fr.c | 3 +++ drivers/net/wan/hdlc_ppp.c | 1 + 3 files changed, 5 insertions(+)
drivers/net/wan/hdlc_cisco.c +1 -0
@@ -118,6 +118,7 @@ static void cisco_keepalive_send(struct net_device *dev, u32 type,skb_put (skb,sizeof (struct cisco_packet )); skb->priority =TC_PRIO_CONTROL ; skb->dev = dev; + skb->protocol =htons (ETH_P_HDLC );skb_reset_network_header (skb);dev_queue_xmit (skb);
drivers/net/wan/hdlc_fr.c +3 -0
@@ -433,6 +433,8 @@ static netdev_tx_t pvc_xmit(struct sk_buff *skb, struct net_device *dev)if (pvc->state.fecn)/* TX Congestion counter */ dev->stats.tx_compressed++; skb->dev = pvc->frad; + skb->protocol =htons (ETH_P_HDLC ); +skb_reset_network_header (skb);dev_queue_xmit (skb);return NETDEV_TX_OK ; }
@@ -555,6 +557,7 @@ static void fr_lmi_send(struct net_device *dev, int fullrep)skb_put (skb, i); skb->priority =TC_PRIO_CONTROL ; skb->dev = dev; + skb->protocol =htons (ETH_P_HDLC );skb_reset_network_header (skb);dev_queue_xmit (skb);
drivers/net/wan/hdlc_ppp.c +1 -0
@@ -251,6 +251,7 @@ static void ppp_tx_cp(struct net_device *dev, u16 pid, u8 code, skb->priority =TC_PRIO_CONTROL ; skb->dev = dev; + skb->protocol =htons (ETH_P_HDLC );skb_reset_network_header (skb);skb_queue_tail (&tx_queue, skb); }
Signature · 1 line
2.25.1
From: Xie He <[email protected]>
Date: Wed, 16 Sep 2020 14:25:07 -0700
Quoted 39 lines
This patch sets
skb->protocolbefore transmitting frames on the HDLC device, so that a user listening on the HDLC device with anAF_PACKETsocket will see outgoing frames'sll_protocolfield correctly set and consistent with that of incoming frames.1. Control frames in
hdlc_ciscoandhdlc_pppWhen these drivers send control frames,
skb->protocolis not set.This value should be set to
htons(ETH_P_HDLC), because when receiving control frames, theirskb->protocolis set tohtons(ETH_P_HDLC).When receiving,
hdlc_type_transinhdlc.his called, which then callscisco_type_transorppp_type_trans. Theskb->protocolof control frames is set tohtons(ETH_P_HDLC)so that the control frames can be received byhdlc_rcvinhdlc.c, which callscisco_rxorppp_rxto process the control frames.2.
hdlc_frWhen this driver sends control frames,
skb->protocolis set to internal values used in this driver.When this driver sends data frames (from upper stacked PVC devices),
skb->protocolis the same as that of the user data packet being sent on the upper PVC device (for normal PVC devices), or ishtons(ETH_P_802_3)(for Ethernet-emulating PVC devices).However,
skb->protocolfor both control frames and data frames should be set tohtons(ETH_P_HDLC), because when receiving, all frames received on the HDLC device will have theirskb->protocolset tohtons(ETH_P_HDLC).When receiving,
hdlc_type_transinhdlc.his called, and because this driver doesn't provide atype_transfunction in structhdlc_proto, all frames will have theirskb->protocolset tohtons(ETH_P_HDLC). The frames are then received byhdlc_rcvinhdlc.c, which callsfr_rxto process the frames (control frames are consumed and data frames are re-received on upper PVC devices).
Quoted 2 lines
Cc Krzysztof Halasa <[email protected]>Signed-off-by Xie He <[email protected]>
Applied, thank you.