This reverts commit 08bee20be29dc46094bd507d3e99116d86da5fce.

The reason why I'm interested in this in the first place is that ptp4l
in raw mode opens two ETH_P_ALL sockets (similar to tcpdump) and
installs a BPF filter on each. All traffic on that interface passes
through those BPF filters, which is sub-optimal from a performance
standpoint. If we could get rid of the VLAN parsing, then we could make
the raw sockets just listen for ETH_P_1588.

The reverted commit says:

    The power profile requires using VLAN priority tagged packets. The
    tags may or may not reach the application. This commit adds code to
    handle the tags in the case that they do appear.

As we know from the IEEE 802.1Q-2018 standard, frames tagged with VLAN
ID 0 (i.e. 802.1p) should be treated as untagged on ingress (i.e. not
dropped due to their VLAN ID) and tagged on egress (i.e. the PCP should
be preserved when forwarding).

There are 2 aspects:

Firstly, if the traffic is always guaranteed to be tagged with 802.1p,
then there's no problem in setting up a VLAN sub-interface with an ID of
0, which will terminate that traffic. Hardware timestamping is passed
just fine.

ip link add link eth1 name eth1.0 type vlan id 0
ptp4l -i eth1.0 -2 -P -m

Secondly, the reverted commit suggests that this might not always be the
case. Some PTP packets might be received with the 802.1p tag, others
without, all within the same PTP domain. This means that we should truly
treat the 802.1p tagged packets as untagged.

We could always do this:

tc qdisc add dev eth1 clsact
tc filter add dev eth1 egress protocol 0x88f7 flower action vlan push id 0
tc filter add dev eth1 ingress protocol 802.1Q flower vlan_id 0 vlan_ethtype 
0x88f7 action vlan pop

With the second command (the pushing of VLAN header on egress) being
optional. In fact, with the current raw socket VLAN code, ptp4l can
still not push an 802.1p header on egress without external help (i.e.
with a filter like the one above). But the key point is that the third
command can be used to treat 802.1p traffic exactly as untagged traffic,
while keeping the application totally unaware. This scales even beyond
L2 PTP, but for some reason it appears that we don't have raw VLAN
parsing for PTP over UDP (i.e. symmetrical capabilities).

Since there is no strong justification to have VLAN awareness in the
linuxptp stack, let's just remove the code to make way for some
performance improvements.

Signed-off-by: Vladimir Oltean <olte...@gmail.com>
---
 ether.h | 10 ----------
 raw.c   | 43 +++++++------------------------------------
 2 files changed, 7 insertions(+), 46 deletions(-)

diff --git a/ether.h b/ether.h
index 8ec96691468b..ae6354b39c23 100644
--- a/ether.h
+++ b/ether.h
@@ -38,16 +38,6 @@ struct eth_hdr {
        uint16_t type;
 } __attribute__((packed));
 
-#define VLAN_HLEN 4
-
-struct vlan_hdr {
-       eth_addr dst;
-       eth_addr src;
-       uint16_t tpid;
-       uint16_t tci;
-       uint16_t type;
-} __attribute__((packed));
-
 #define OFF_ETYPE (2 * sizeof(eth_addr))
 
 #endif
diff --git a/raw.c b/raw.c
index 0bd15b08e0a2..b933c4518ea6 100644
--- a/raw.c
+++ b/raw.c
@@ -50,28 +50,21 @@ struct raw {
        struct address src_addr;
        struct address ptp_addr;
        struct address p2p_addr;
-       int vlan;
 };
 
 #define OP_AND  (BPF_ALU | BPF_AND | BPF_K)
 #define OP_JEQ  (BPF_JMP | BPF_JEQ | BPF_K)
-#define OP_JUN  (BPF_JMP | BPF_JA)
 #define OP_LDB  (BPF_LD  | BPF_B   | BPF_ABS)
 #define OP_LDH  (BPF_LD  | BPF_H   | BPF_ABS)
 #define OP_RETK (BPF_RET | BPF_K)
 
 #define PTP_GEN_BIT 0x08 /* indicates general message, if set in message type 
*/
 
-#define N_RAW_FILTER    12
-#define RAW_FILTER_TEST 9
+#define N_RAW_FILTER    7
+#define RAW_FILTER_TEST 4
 
 static struct sock_filter raw_filter[N_RAW_FILTER] = {
        {OP_LDH,  0, 0, OFF_ETYPE   },
-       {OP_JEQ,  0, 4, ETH_P_8021Q          }, /*f goto non-vlan block*/
-       {OP_LDH,  0, 0, OFF_ETYPE + 4        },
-       {OP_JEQ,  0, 7, ETH_P_1588           }, /*f goto reject*/
-       {OP_LDB,  0, 0, ETH_HLEN + VLAN_HLEN },
-       {OP_JUN,  0, 0, 2                    }, /*goto test general bit*/
        {OP_JEQ,  0, 4, ETH_P_1588  }, /*f goto reject*/
        {OP_LDB,  0, 0, ETH_HLEN    },
        {OP_AND,  0, 0, PTP_GEN_BIT }, /*test general bit*/
@@ -265,38 +258,16 @@ no_mac:
 static int raw_recv(struct transport *t, int fd, void *buf, int buflen,
                    struct address *addr, struct hw_timestamp *hwts)
 {
-       int cnt, hlen;
        unsigned char *ptr = buf;
-       struct eth_hdr *hdr;
-       struct raw *raw = container_of(t, struct raw, t);
+       int cnt;
 
-       if (raw->vlan) {
-               hlen = sizeof(struct vlan_hdr);
-       } else {
-               hlen = sizeof(struct eth_hdr);
-       }
-       ptr    -= hlen;
-       buflen += hlen;
-       hdr = (struct eth_hdr *) ptr;
+       ptr    -= sizeof(struct eth_hdr);
+       buflen += sizeof(struct eth_hdr);
 
        cnt = sk_receive(fd, ptr, buflen, addr, hwts, MSG_DONTWAIT);
+       if (cnt >= sizeof(struct eth_hdr))
+               cnt -= sizeof(struct eth_hdr);
 
-       if (cnt >= 0)
-               cnt -= hlen;
-       if (cnt < 0)
-               return cnt;
-
-       if (raw->vlan) {
-               if (ETH_P_1588 == ntohs(hdr->type)) {
-                       pr_notice("raw: disabling VLAN mode");
-                       raw->vlan = 0;
-               }
-       } else {
-               if (ETH_P_8021Q == ntohs(hdr->type)) {
-                       pr_notice("raw: switching to VLAN mode");
-                       raw->vlan = 1;
-               }
-       }
        return cnt;
 }
 
-- 
2.25.1



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to