I would like to Tag my Ethernetpacket with a Dot1Q layer. I want to insert it between the EthernetLayer and IPv4Layer/ARP etc. This is the code that I tried, but I don't know what is wrong:
sls := []gopacket.SerializableLayer{}
for _, layer := range packet.Layers() {
sl, ok := layer.(gopacket.SerializableLayer)
if !ok {
log.Printf("layer %s is not serializable", layer.LayerType().String())
}
sls = append(sls, sl)
if !tagged && layer.LayerType() == layers.LayerTypeEthernet {
vlan := &layers.Dot1Q{
VLANIdentifier: vid,
Type: layers.EthernetTypeDot1Q,
}
sls = append(sls, vlan.(gopacket.SerializableLayer))
}
}
I get the following error:
invalid type assertion: vlan.(gopacket.SerializableLayer) (non-interface type *layers.Dot1Q on left)