github.com/vishvananda/netlink@v1.3.0/protinfo_test.go (about) 1 //go:build linux 2 // +build linux 3 4 package netlink 5 6 import ( 7 "testing" 8 ) 9 10 func TestProtinfo(t *testing.T) { 11 tearDown := setUpNetlinkTest(t) 12 defer tearDown() 13 master := &Bridge{LinkAttrs: LinkAttrs{Name: "foo"}} 14 if err := LinkAdd(master); err != nil { 15 t.Fatal(err) 16 } 17 iface1 := &Dummy{LinkAttrs{Name: "bar1", MasterIndex: master.Index}} 18 iface2 := &Dummy{LinkAttrs{Name: "bar2", MasterIndex: master.Index}} 19 iface3 := &Dummy{LinkAttrs{Name: "bar3"}} 20 iface4 := &Dummy{LinkAttrs{Name: "bar4", MasterIndex: master.Index}} 21 22 if err := LinkAdd(iface1); err != nil { 23 t.Fatal(err) 24 } 25 if err := LinkAdd(iface2); err != nil { 26 t.Fatal(err) 27 } 28 if err := LinkAdd(iface3); err != nil { 29 t.Fatal(err) 30 } 31 if err := LinkAdd(iface4); err != nil { 32 t.Fatal(err) 33 } 34 35 oldpi1, err := LinkGetProtinfo(iface1) 36 if err != nil { 37 t.Fatal(err) 38 } 39 oldpi2, err := LinkGetProtinfo(iface2) 40 if err != nil { 41 t.Fatal(err) 42 } 43 oldpi4, err := LinkGetProtinfo(iface4) 44 if err != nil { 45 t.Fatal(err) 46 } 47 48 if err := LinkSetHairpin(iface1, true); err != nil { 49 t.Fatal(err) 50 } 51 52 if err := LinkSetRootBlock(iface1, true); err != nil { 53 t.Fatal(err) 54 } 55 56 pi1, err := LinkGetProtinfo(iface1) 57 if err != nil { 58 t.Fatal(err) 59 } 60 if !pi1.Hairpin { 61 t.Fatalf("Hairpin mode is not enabled for %s, but should", iface1.Name) 62 } 63 if !pi1.RootBlock { 64 t.Fatalf("RootBlock is not enabled for %s, but should", iface1.Name) 65 } 66 if pi1.Isolated { 67 t.Fatalf("Isolated mode is enabled for %s, but shouldn't", iface1.Name) 68 } 69 if pi1.ProxyArp != oldpi1.ProxyArp { 70 t.Fatalf("ProxyArp field was changed for %s but shouldn't", iface1.Name) 71 } 72 if pi1.ProxyArpWiFi != oldpi1.ProxyArp { 73 t.Fatalf("ProxyArpWiFi ProxyArp field was changed for %s but shouldn't", iface1.Name) 74 } 75 if pi1.Guard != oldpi1.Guard { 76 t.Fatalf("Guard field was changed for %s but shouldn't", iface1.Name) 77 } 78 if pi1.FastLeave != oldpi1.FastLeave { 79 t.Fatalf("FastLeave field was changed for %s but shouldn't", iface1.Name) 80 } 81 if pi1.Learning != oldpi1.Learning { 82 t.Fatalf("Learning field was changed for %s but shouldn't", iface1.Name) 83 } 84 if pi1.Flood != oldpi1.Flood { 85 t.Fatalf("Flood field was changed for %s but shouldn't", iface1.Name) 86 } 87 if pi1.NeighSuppress != oldpi1.NeighSuppress { 88 t.Fatalf("NeighSuppress field was changed for %s but shouldn't", iface1.Name) 89 } 90 91 if err := LinkSetGuard(iface2, true); err != nil { 92 t.Fatal(err) 93 } 94 if err := LinkSetLearning(iface2, false); err != nil { 95 t.Fatal(err) 96 } 97 pi2, err := LinkGetProtinfo(iface2) 98 if err != nil { 99 t.Fatal(err) 100 } 101 if pi2.Hairpin { 102 t.Fatalf("Hairpin mode is enabled for %s, but shouldn't", iface2.Name) 103 } 104 if !pi2.Guard { 105 t.Fatalf("Guard is not enabled for %s, but should", iface2.Name) 106 } 107 if pi2.ProxyArp != oldpi2.ProxyArp { 108 t.Fatalf("ProxyArp field was changed for %s but shouldn't", iface2.Name) 109 } 110 if pi2.ProxyArpWiFi != oldpi2.ProxyArpWiFi { 111 t.Fatalf("ProxyArpWiFi field was changed for %s but shouldn't", iface2.Name) 112 } 113 if pi2.Learning { 114 t.Fatalf("Learning is enabled for %s, but shouldn't", iface2.Name) 115 } 116 if pi2.RootBlock != oldpi2.RootBlock { 117 t.Fatalf("RootBlock field was changed for %s but shouldn't", iface2.Name) 118 } 119 if pi2.FastLeave != oldpi2.FastLeave { 120 t.Fatalf("FastLeave field was changed for %s but shouldn't", iface2.Name) 121 } 122 if pi2.Flood != oldpi2.Flood { 123 t.Fatalf("Flood field was changed for %s but shouldn't", iface2.Name) 124 } 125 if pi2.NeighSuppress != oldpi2.NeighSuppress { 126 t.Fatalf("NeighSuppress field was changed for %s but shouldn't", iface2.Name) 127 } 128 129 if err := LinkSetHairpin(iface3, true); err == nil || err.Error() != "operation not supported" { 130 t.Fatalf("Set protinfo attrs for link without master is not supported, but err: %s", err) 131 } 132 133 // Setting kernel requirement for next tests which require BR_PROXYARP 134 minKernelRequired(t, 3, 19) 135 136 if err := LinkSetBrProxyArp(iface4, true); err != nil { 137 t.Fatal(err) 138 } 139 140 if err := LinkSetBrProxyArpWiFi(iface4, true); err != nil { 141 t.Fatal(err) 142 } 143 pi4, err := LinkGetProtinfo(iface4) 144 if err != nil { 145 t.Fatal(err) 146 } 147 if pi4.Hairpin != oldpi4.Hairpin { 148 t.Fatalf("Hairpin field was changed for %s but shouldn't", iface4.Name) 149 } 150 if pi4.Guard != oldpi4.Guard { 151 t.Fatalf("Guard field was changed for %s but shouldn't", iface4.Name) 152 } 153 if pi4.Learning != oldpi4.Learning { 154 t.Fatalf("Learning field was changed for %s but shouldn't", iface4.Name) 155 } 156 if !pi4.ProxyArp { 157 t.Fatalf("ProxyArp is not enabled for %s, but should", iface4.Name) 158 } 159 if !pi4.ProxyArpWiFi { 160 t.Fatalf("ProxyArpWiFi is not enabled for %s, but should", iface4.Name) 161 } 162 if pi4.RootBlock != oldpi4.RootBlock { 163 t.Fatalf("RootBlock field was changed for %s but shouldn't", iface4.Name) 164 } 165 if pi4.FastLeave != oldpi4.FastLeave { 166 t.Fatalf("FastLeave field was changed for %s but shouldn't", iface4.Name) 167 } 168 if pi4.Flood != oldpi4.Flood { 169 t.Fatalf("Flood field was changed for %s but shouldn't", iface4.Name) 170 } 171 172 // BR_NEIGH_SUPPRESS added on 4.15 173 minKernelRequired(t, 4, 15) 174 175 if err := LinkSetBrNeighSuppress(iface1, true); err != nil { 176 t.Fatal(err) 177 } 178 pi1, err = LinkGetProtinfo(iface1) 179 if err != nil { 180 t.Fatal(err) 181 } 182 if !pi1.NeighSuppress { 183 t.Fatalf("NeighSuppress is not enabled for %s but should", iface1.Name) 184 } 185 186 // Setting kernel requirement for next tests which require BRPORT_ISOLATED 187 minKernelRequired(t, 4, 18) 188 189 if err := LinkSetIsolated(iface1, true); err != nil { 190 t.Fatal(err) 191 } 192 pi1, err = LinkGetProtinfo(iface1) 193 if err != nil { 194 t.Fatal(err) 195 } 196 if !pi1.Isolated { 197 t.Fatalf("Isolated mode is not enabled for %s, but should", iface1.Name) 198 } 199 }