@@ -589,6 +589,109 @@ func (e *BpfEncap) Equal(x Encap) bool {
589
589
return true
590
590
}
591
591
592
+ // IP6tnlEncap definition
593
+ type IP6tnlEncap struct {
594
+ ID uint64
595
+ Dst net.IP
596
+ Src net.IP
597
+ Hoplimit uint8
598
+ TC uint8
599
+ Flags uint16
600
+ }
601
+
602
+ func (e * IP6tnlEncap ) Type () int {
603
+ return nl .LWTUNNEL_ENCAP_IP6
604
+ }
605
+
606
+ func (e * IP6tnlEncap ) Decode (buf []byte ) error {
607
+ attrs , err := nl .ParseRouteAttr (buf )
608
+ if err != nil {
609
+ return err
610
+ }
611
+ for _ , attr := range attrs {
612
+ switch attr .Attr .Type {
613
+ case nl .LWTUNNEL_IP6_ID :
614
+ e .ID = uint64 (native .Uint64 (attr .Value [0 :4 ]))
615
+ case nl .LWTUNNEL_IP6_DST :
616
+ e .Dst = net .IP (attr .Value [:])
617
+ case nl .LWTUNNEL_IP6_SRC :
618
+ e .Src = net .IP (attr .Value [:])
619
+ case nl .LWTUNNEL_IP6_HOPLIMIT :
620
+ e .Hoplimit = attr .Value [0 ]
621
+ case nl .LWTUNNEL_IP6_TC :
622
+ // e.TC = attr.Value[0]
623
+ err = fmt .Errorf ("decoding TC in IP6tnlEncap is not supported" )
624
+ case nl .LWTUNNEL_IP6_FLAGS :
625
+ // e.Flags = uint16(native.Uint16(attr.Value[0:2]))
626
+ err = fmt .Errorf ("decoding FLAG in IP6tnlEncap is not supported" )
627
+ case nl .LWTUNNEL_IP6_PAD :
628
+ err = fmt .Errorf ("decoding PAD in IP6tnlEncap is not supported" )
629
+ case nl .LWTUNNEL_IP6_OPTS :
630
+ err = fmt .Errorf ("decoding OPTS in IP6tnlEncap is not supported" )
631
+ }
632
+ }
633
+ return err
634
+ }
635
+
636
+ func (e * IP6tnlEncap ) Encode () ([]byte , error ) {
637
+
638
+ final := []byte {}
639
+
640
+ resID := make ([]byte , 12 )
641
+ native .PutUint16 (resID , 12 ) // 2+2+8
642
+ native .PutUint16 (resID [2 :], nl .LWTUNNEL_IP6_ID )
643
+ native .PutUint64 (resID [4 :], 0 )
644
+ final = append (final , resID ... )
645
+
646
+ resDst := make ([]byte , 4 )
647
+ native .PutUint16 (resDst , 20 ) // 2+2+16
648
+ native .PutUint16 (resDst [2 :], nl .LWTUNNEL_IP6_DST )
649
+ resDst = append (resDst , e .Dst ... )
650
+ final = append (final , resDst ... )
651
+
652
+ resSrc := make ([]byte , 4 )
653
+ native .PutUint16 (resSrc , 20 )
654
+ native .PutUint16 (resSrc [2 :], nl .LWTUNNEL_IP6_SRC )
655
+ resSrc = append (resSrc , e .Src ... )
656
+ final = append (final , resSrc ... )
657
+
658
+ // resTc := make([]byte, 5)
659
+ // native.PutUint16(resTc, 5)
660
+ // native.PutUint16(resTc[2:], nl.LWTUNNEL_IP6_TC)
661
+ // resTc[4] = e.TC
662
+ // final = append(final,resTc...)
663
+
664
+ resHops := make ([]byte , 5 )
665
+ native .PutUint16 (resHops , 5 )
666
+ native .PutUint16 (resHops [2 :], nl .LWTUNNEL_IP6_HOPLIMIT )
667
+ resHops [4 ] = e .Hoplimit
668
+ final = append (final , resHops ... )
669
+
670
+ // resFlags := make([]byte, 6)
671
+ // native.PutUint16(resFlags, 6)
672
+ // native.PutUint16(resFlags[2:], nl.LWTUNNEL_IP6_FLAGS)
673
+ // native.PutUint16(resFlags[4:], e.Flags)
674
+ // final = append(final,resFlags...)
675
+
676
+ return final , nil
677
+ }
678
+
679
+ func (e * IP6tnlEncap ) String () string {
680
+ return fmt .Sprintf ("id %d src %s dst %s hoplimit %d tc %d flags 0x%.4x" , e .ID , e .Src , e .Dst , e .Hoplimit , e .TC , e .Flags )
681
+ }
682
+
683
+ func (e * IP6tnlEncap ) Equal (x Encap ) bool {
684
+ o , ok := x .(* IP6tnlEncap )
685
+ if ! ok {
686
+ return false
687
+ }
688
+
689
+ if e .ID != o .ID || e .Flags != o .Flags || e .Hoplimit != o .Hoplimit || e .Src .Equal (o .Src ) || e .Dst .Equal (o .Dst ) || e .TC != o .TC {
690
+ return false
691
+ }
692
+ return true
693
+ }
694
+
592
695
type Via struct {
593
696
AddrFamily int
594
697
Addr net.IP
0 commit comments