Skip to content

Commit c0d89e6

Browse files
committed
fix: use ip.To4()
1 parent 7b5e353 commit c0d89e6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

nl/tc_linux.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -1239,8 +1239,8 @@ const (
12391239
)
12401240

12411241
// /* TCA_PEDIT_KEY_EX_HDR_TYPE_NETWROK is a special case for legacy users. It
1242-
// * means no specific header type - offset is relative to the network layer
1243-
// */
1242+
// - means no specific header type - offset is relative to the network layer
1243+
// */
12441244
type PeditHeaderType uint16
12451245

12461246
const (
@@ -1460,15 +1460,15 @@ func (p *TcPedit) SetIPv6Src(ip6 net.IP) {
14601460

14611461
func (p *TcPedit) SetDstIP(ip net.IP) {
14621462
if ip.To4() != nil {
1463-
p.SetIPv4Dst(ip)
1463+
p.SetIPv4Dst(ip.To4())
14641464
} else {
14651465
p.SetIPv6Dst(ip)
14661466
}
14671467
}
14681468

14691469
func (p *TcPedit) SetSrcIP(ip net.IP) {
14701470
if ip.To4() != nil {
1471-
p.SetIPv4Src(ip)
1471+
p.SetIPv4Src(ip.To4())
14721472
} else {
14731473
p.SetIPv6Src(ip)
14741474
}
@@ -1533,7 +1533,7 @@ func (p *TcPedit) SetIPv6Dst(ip6 net.IP) {
15331533
}
15341534

15351535
func (p *TcPedit) SetIPv4Src(ip net.IP) {
1536-
u32 := NativeEndian().Uint32(ip[12:16])
1536+
u32 := NativeEndian().Uint32(ip[:4])
15371537

15381538
tKey := TcPeditKey{}
15391539
tKeyEx := TcPeditKeyEx{}
@@ -1549,7 +1549,7 @@ func (p *TcPedit) SetIPv4Src(ip net.IP) {
15491549
}
15501550

15511551
func (p *TcPedit) SetIPv4Dst(ip net.IP) {
1552-
u32 := NativeEndian().Uint32(ip[12:16])
1552+
u32 := NativeEndian().Uint32(ip[:4])
15531553

15541554
tKey := TcPeditKey{}
15551555
tKeyEx := TcPeditKeyEx{}

0 commit comments

Comments
 (0)