Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit 6f3f221

Browse files
authored
Merge pull request #22 from aojea/panic1
Don't panic on small packets
2 parents 0d435a2 + d97c6bc commit 6f3f221

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pkg/networkpolicy/controller_test.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"k8s.io/component-base/logs"
1515
"k8s.io/klog/v2"
1616
"k8s.io/utils/ptr"
17-
"sigs.k8s.io/knftables"
1817
)
1918

2019
type netpolTweak func(networkPolicy *networkingv1.NetworkPolicy)
@@ -102,15 +101,13 @@ type networkpolicyController struct {
102101
}
103102

104103
func newController() *networkpolicyController {
105-
nft := knftables.NewFake(knftables.InetFamily, "kube-netpol")
106104
client := fake.NewSimpleClientset()
107105
informersFactory := informers.NewSharedInformerFactory(client, 0)
108106
controller := NewController(client,
109107
informersFactory.Networking().V1().NetworkPolicies(),
110108
informersFactory.Core().V1().Namespaces(),
111109
informersFactory.Core().V1().Pods(),
112-
nft,
113-
100,
110+
Config{},
114111
)
115112
controller.networkpoliciesSynced = alwaysReady
116113
controller.namespacesSynced = alwaysReady

pkg/networkpolicy/packet.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,17 @@ func parsePacket(b []byte) (packet, error) {
6161
return t, fmt.Errorf("unknown versions %d", version)
6262
}
6363

64+
var dataOffset int
6465
switch protocol {
6566
case 6:
6667
t.proto = v1.ProtocolTCP
68+
dataOffset = int(b[hdrlen+12] >> 4) // data offset
6769
case 17:
6870
t.proto = v1.ProtocolUDP
71+
dataOffset = hdrlen + 8 // data starts after
6972
case 132:
7073
t.proto = v1.ProtocolSCTP
74+
dataOffset = hdrlen + 8
7175
default:
7276
return t, fmt.Errorf("unknown protocol %d", protocol)
7377
}
@@ -76,7 +80,6 @@ func parsePacket(b []byte) (packet, error) {
7680
t.dstPort = int(binary.BigEndian.Uint16(b[hdrlen+2 : hdrlen+4]))
7781
// Obtain the offset of the payload
7882
// TODO allow to filter by the payload
79-
dataOffset := int(b[hdrlen+12] >> 4)
8083
if len(b) >= hdrlen+dataOffset {
8184
t.payload = b[hdrlen+dataOffset:]
8285
}

0 commit comments

Comments
 (0)