@@ -3,8 +3,6 @@ package networkpolicy
3
3
import (
4
4
"bytes"
5
5
"context"
6
- "encoding/binary"
7
- "encoding/hex"
8
6
"fmt"
9
7
"net"
10
8
"os/exec"
@@ -387,10 +385,6 @@ func (c *Controller) syncIptablesRules() {
387
385
if err := c .ipt .InsertUnique ("filter" , "FORWARD" , 1 , queueRule ... ); err != nil {
388
386
klog .Infof ("error syncing iptables rule %v" , err )
389
387
}
390
-
391
- if err := c .ipt .InsertUnique ("filter" , "OUTPUT" , 1 , queueRule ... ); err != nil {
392
- klog .Infof ("error syncing iptables rule %v" , err )
393
- }
394
388
}
395
389
396
390
func (c * Controller ) cleanIptablesRules () {
@@ -402,10 +396,6 @@ func (c *Controller) cleanIptablesRules() {
402
396
if err := c .ipt .Delete ("filter" , "FORWARD" , queueRule ... ); err != nil {
403
397
klog .Infof ("error deleting iptables rule %v" , err )
404
398
}
405
-
406
- if err := c .ipt .Delete ("filter" , "OUTPUT" , queueRule ... ); err != nil {
407
- klog .Infof ("error deleting iptables rule %v" , err )
408
- }
409
399
}
410
400
411
401
func (c * Controller ) getNetworkPoliciesForPod (pod * v1.Pod ) []* networkingv1.NetworkPolicy {
@@ -766,77 +756,3 @@ func (c *Controller) evaluatePorts(networkPolicyPorts []networkingv1.NetworkPoli
766
756
}
767
757
return false
768
758
}
769
-
770
- type packet struct {
771
- family v1.IPFamily
772
- srcIP net.IP
773
- dstIP net.IP
774
- proto v1.Protocol
775
- srcPort int
776
- dstPort int
777
- payload []byte
778
- }
779
-
780
- func (p packet ) String () string {
781
- return fmt .Sprintf ("%s:%d %s:%d %s :: %s" , p .srcIP .String (), p .srcPort , p .dstIP .String (), p .dstPort , p .proto , hex .Dump (p .payload ))
782
- }
783
-
784
- // https://en.wikipedia.org/wiki/Internet_Protocol_version_4#Packet_structure
785
- // https://en.wikipedia.org/wiki/IPv6_packet
786
- // https://github.com/golang/net/blob/master/ipv4/header.go
787
- func parsePacket (b []byte ) (packet , error ) {
788
- t := packet {}
789
- if b == nil {
790
- return t , fmt .Errorf ("empty payload" )
791
- }
792
- version := int (b [0 ] >> 4 )
793
- // initialize variables
794
- hdrlen := - 1
795
- protocol := - 1
796
- switch version {
797
- case 4 :
798
- t .family = v1 .IPv4Protocol
799
- hdrlen = int (b [0 ]& 0x0f ) << 2
800
- if len (b ) < hdrlen + 4 {
801
- return t , fmt .Errorf ("payload to short, received %d expected at least %d" , len (b ), hdrlen + 4 )
802
- }
803
- t .srcIP = net .IPv4 (b [12 ], b [13 ], b [14 ], b [15 ])
804
- t .dstIP = net .IPv4 (b [16 ], b [17 ], b [18 ], b [19 ])
805
- protocol = int (b [9 ])
806
- case 6 :
807
- t .family = v1 .IPv6Protocol
808
- hdrlen = 40
809
- if len (b ) < hdrlen + 4 {
810
- return t , fmt .Errorf ("payload to short, received %d expected at least %d" , len (b ), hdrlen + 4 )
811
- }
812
- t .srcIP = make (net.IP , net .IPv6len )
813
- copy (t .srcIP , b [8 :24 ])
814
- t .dstIP = make (net.IP , net .IPv6len )
815
- copy (t .dstIP , b [24 :40 ])
816
- // NextHeader (not extension headers supported)
817
- protocol = int (b [6 ])
818
- default :
819
- return t , fmt .Errorf ("unknown versions %d" , version )
820
- }
821
-
822
- switch protocol {
823
- case 6 :
824
- t .proto = v1 .ProtocolTCP
825
- case 17 :
826
- t .proto = v1 .ProtocolUDP
827
- case 132 :
828
- t .proto = v1 .ProtocolSCTP
829
- default :
830
- return t , fmt .Errorf ("unknown protocol %d" , protocol )
831
- }
832
- // TCP, UDP and SCTP srcPort and dstPort are the first 4 bytes after the IP header
833
- t .srcPort = int (binary .BigEndian .Uint16 (b [hdrlen : hdrlen + 2 ]))
834
- t .dstPort = int (binary .BigEndian .Uint16 (b [hdrlen + 2 : hdrlen + 4 ]))
835
- // Obtain the offset of the payload
836
- // TODO allow to filter by the payload
837
- dataOffset := int (b [hdrlen + 12 ] >> 4 )
838
- if len (b ) >= hdrlen + dataOffset {
839
- t .payload = b [hdrlen + dataOffset :]
840
- }
841
- return t , nil
842
- }
0 commit comments