|
| 1 | +//go:build linux |
1 | 2 | // +build linux |
2 | 3 |
|
3 | 4 | package netlink |
4 | 5 |
|
5 | 6 | import ( |
| 7 | + "net" |
6 | 8 | "testing" |
7 | 9 | ) |
8 | 10 |
|
@@ -33,20 +35,50 @@ func TestFouDeserializeMsg(t *testing.T) { |
33 | 35 | } |
34 | 36 | } |
35 | 37 |
|
36 | | - // deserialize truncated attribute header |
37 | | - msg = []byte{3, 1, 0, 0, 5, 0} |
38 | | - if _, err := deserializeFouMsg(msg); err == nil { |
39 | | - t.Error("expected attribute header truncated error") |
40 | | - } else if err != ErrAttrHeaderTruncated { |
41 | | - t.Errorf("unexpected error: %s", err.Error()) |
| 38 | + // deserialize a valid message(kernel >= 5.2) |
| 39 | + msg = []byte{3, 1, 0, 0, 5, 0, 2, 0, 2, 0, 0, 0, 6, 0, 1, 0, 43, 103, 0, 0, 6, 0, 10, 0, 86, 206, 0, 0, 5, 0, 3, 0, 0, 0, 0, 0, 5, 0, 4, 0, 2, 0, 0, 0, 8, 0, 11, 0, 0, 0, 0, 0, 8, 0, 6, 0, 1, 2, 3, 4, 8, 0, 8, 0, 5, 6, 7, 8} |
| 40 | + if fou, err := deserializeFouMsg(msg); err != nil { |
| 41 | + t.Error(err.Error()) |
| 42 | + } else { |
| 43 | + if fou.Family != FAMILY_V4 { |
| 44 | + t.Errorf("expected family %d, got %d", FAMILY_V4, fou.Family) |
| 45 | + } |
| 46 | + |
| 47 | + if fou.Port != 11111 { |
| 48 | + t.Errorf("expected port 5555, got %d", fou.Port) |
| 49 | + } |
| 50 | + |
| 51 | + if fou.Protocol != 0 { // gue |
| 52 | + t.Errorf("expected protocol 0, got %d", fou.Protocol) |
| 53 | + } |
| 54 | + |
| 55 | + if fou.IfIndex != 0 { |
| 56 | + t.Errorf("expected ifindex 0, got %d", fou.Protocol) |
| 57 | + } |
| 58 | + |
| 59 | + if fou.EncapType != FOU_ENCAP_GUE { |
| 60 | + t.Errorf("expected encap type %d, got %d", FOU_ENCAP_GUE, fou.EncapType) |
| 61 | + } |
| 62 | + |
| 63 | + if expected := net.IPv4(1, 2, 3, 4); !fou.Local.Equal(expected) { |
| 64 | + t.Errorf("expected local %v, got %v", expected, fou.Local) |
| 65 | + } |
| 66 | + |
| 67 | + if expected := net.IPv4(5, 6, 7, 8); !fou.Peer.Equal(expected) { |
| 68 | + t.Errorf("expected peer %v, got %v", expected, fou.Peer) |
| 69 | + } |
| 70 | + |
| 71 | + if fou.PeerPort != 22222 { |
| 72 | + t.Errorf("expected peer port 0, got %d", fou.PeerPort) |
| 73 | + } |
42 | 74 | } |
43 | 75 |
|
44 | | - // deserialize truncated attribute header |
45 | | - msg = []byte{3, 1, 0, 0, 5, 0, 2, 0, 2, 0, 0} |
46 | | - if _, err := deserializeFouMsg(msg); err == nil { |
47 | | - t.Error("expected attribute body truncated error") |
48 | | - } else if err != ErrAttrBodyTruncated { |
| 76 | + // unknown attribute should be skipped |
| 77 | + msg = []byte{3, 1, 0, 0, 5, 0, 112, 0, 2, 0, 0, 0, 5, 0, 2, 0, 2, 0, 0} |
| 78 | + if fou, err := deserializeFouMsg(msg); err != nil { |
49 | 79 | t.Errorf("unexpected error: %s", err.Error()) |
| 80 | + } else if fou.Family != 2 { |
| 81 | + t.Errorf("expected family 2, got %d", fou.Family) |
50 | 82 | } |
51 | 83 | } |
52 | 84 |
|
|
0 commit comments