From: Mika Paulamäki <mika.paulam...@fi.abb.com>

Add option to include and configure VLAN tags
when using transport type IEEE 802.3 (Ethernet).

Configurable via configuration file using new parameters:
 - "raw_send_vlan_enable", default = 0 (off), range = 0..1
 - "raw_send_vlan_id" default = 0, range = 0..4095
 - "raw_send_vlan_priority", default = 4, range = 0..7

Signed-off-by: Mika Paulamäki <mika.paulam...@fi.abb.com>
Signed-off-by: Magnus Armholt <magnus.armh...@fi.abb.com>
---
 config.c |  3 +++
 raw.c    | 47 +++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/config.c b/config.c
index e454c91..d97be72 100644
--- a/config.c
+++ b/config.c
@@ -303,6 +303,9 @@ struct config_item config_tab[] = {
        GLOB_ITEM_STR("productDescription", ";;"),
        PORT_ITEM_STR("ptp_dst_mac", "01:1B:19:00:00:00"),
        PORT_ITEM_STR("p2p_dst_mac", "01:80:C2:00:00:0E"),
+       GLOB_ITEM_INT("raw_send_vlan_enable", 0, 0, 1),
+       GLOB_ITEM_INT("raw_send_vlan_id", 0, 0, 4095),
+       GLOB_ITEM_INT("raw_send_vlan_priority", 4, 0, 7),
        GLOB_ITEM_STR("revisionData", ";;"),
        GLOB_ITEM_INT("sanity_freq_limit", 200000000, 0, INT_MAX),
        PORT_ITEM_INT("serverOnly", 0, 0, 1),
diff --git a/raw.c b/raw.c
index b9abe7a..809db9e 100644
--- a/raw.c
+++ b/raw.c
@@ -374,7 +374,10 @@ static int raw_send(struct transport *t, struct fdarray 
*fda,
        struct raw *raw = container_of(t, struct raw, t);
        ssize_t cnt;
        unsigned char pkt[1600], *ptr = buf;
+       struct vlan_hdr *vlan_hdr;
        struct eth_hdr *hdr;
+       int vlan_priority;
+       int vlan_id;
        int fd = -1;
 
        switch (event) {
@@ -389,17 +392,45 @@ static int raw_send(struct transport *t, struct fdarray 
*fda,
                break;
        }
 
-       ptr -= sizeof(*hdr);
-       len += sizeof(*hdr);
-
-       if (!addr)
+       if (!addr) {
                addr = peer ? &raw->p2p_addr : &raw->ptp_addr;
+       }
 
-       hdr = (struct eth_hdr *) ptr;
-       addr_to_mac(&hdr->dst, addr);
-       addr_to_mac(&hdr->src, &raw->src_addr);
+       if (config_get_int(t->cfg, NULL, "raw_send_vlan_enable")) {
+               /* Use Ethernet + VLAN header for sent messages. */
+
+               ptr -= sizeof(*vlan_hdr);
+               len += sizeof(*vlan_hdr);
+
+               vlan_hdr = (struct vlan_hdr *) ptr;
+               addr_to_mac(&vlan_hdr->dst, addr);
+               addr_to_mac(&vlan_hdr->src, &raw->src_addr);
+
+               vlan_hdr->tpid = htons(ETH_P_8021Q);
 
-       hdr->type = htons(ETH_P_1588);
+               vlan_id = config_get_int(t->cfg, NULL, "raw_send_vlan_id");
+               vlan_priority = config_get_int(t->cfg, NULL, 
"raw_send_vlan_priority");
+               /*
+                * VLAN TCI = PCP|DEI|VID
+                *      PCP = Priority code point (3-bit)
+                *              DEI = Drop eligible indicator (1-bit) = 0
+                *              VID = VLAN identifier (12-bit)
+               */
+               vlan_hdr->tci = htons((vlan_priority << 13) | (vlan_id & 
0x0FFF));
+
+               vlan_hdr->type = htons(ETH_P_1588);
+       } else {
+               /* Use Ethernet header for sent messages. */
+
+               ptr -= sizeof(*hdr);
+               len += sizeof(*hdr);
+
+               hdr = (struct eth_hdr *) ptr;
+               addr_to_mac(&hdr->dst, addr);
+               addr_to_mac(&hdr->src, &raw->src_addr);
+
+               hdr->type = htons(ETH_P_1588);
+       }
 
        cnt = send(fd, ptr, len, 0);
        if (cnt < 1) {
-- 
2.34.1



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

Reply via email to