mirror of https://github.com/vishvananda/netlink
RouteUpdate gains NlFlags field
It allows to distinguish between a new created route or a replaced one. Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
This commit is contained in:
parent
8fa22700b3
commit
7f562ed576
9
route.go
9
route.go
|
@ -154,8 +154,15 @@ type flagString struct {
|
|||
}
|
||||
|
||||
// RouteUpdate is sent when a route changes - type is RTM_NEWROUTE or RTM_DELROUTE
|
||||
|
||||
// NlFlags is only non-zero for RTM_NEWROUTE, the following flags can be set:
|
||||
// - unix.NLM_F_REPLACE - Replace existing matching config object with this request
|
||||
// - unix.NLM_F_EXCL - Don't replace the config object if it already exists
|
||||
// - unix.NLM_F_CREATE - Create config object if it doesn't already exist
|
||||
// - unix.NLM_F_APPEND - Add to the end of the object list
|
||||
type RouteUpdate struct {
|
||||
Type uint16
|
||||
Type uint16
|
||||
NlFlags uint16
|
||||
Route
|
||||
}
|
||||
|
||||
|
|
|
@ -1687,7 +1687,11 @@ func routeSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- RouteUpdate, done <
|
|||
}
|
||||
continue
|
||||
}
|
||||
ch <- RouteUpdate{Type: m.Header.Type, Route: route}
|
||||
ch <- RouteUpdate{
|
||||
Type: m.Header.Type,
|
||||
NlFlags: m.Header.Flags & (unix.NLM_F_REPLACE | unix.NLM_F_EXCL | unix.NLM_F_CREATE | unix.NLM_F_APPEND),
|
||||
Route: route,
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -543,13 +543,14 @@ func TestRouteAddIncomplete(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// expectNeighUpdate returns whether the expected updated is received within one minute.
|
||||
func expectRouteUpdate(ch <-chan RouteUpdate, t uint16, dst net.IP) bool {
|
||||
// expectRouteUpdate returns whether the expected updated is received within one minute.
|
||||
func expectRouteUpdate(ch <-chan RouteUpdate, t, f uint16, dst net.IP) bool {
|
||||
for {
|
||||
timeout := time.After(time.Minute)
|
||||
select {
|
||||
case update := <-ch:
|
||||
if update.Type == t &&
|
||||
update.NlFlags == f &&
|
||||
update.Route.Dst != nil &&
|
||||
update.Route.Dst.IP.Equal(dst) {
|
||||
return true
|
||||
|
@ -594,13 +595,13 @@ func TestRouteSubscribe(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !expectRouteUpdate(ch, unix.RTM_NEWROUTE, dst.IP) {
|
||||
if !expectRouteUpdate(ch, unix.RTM_NEWROUTE, unix.NLM_F_EXCL|unix.NLM_F_CREATE, dst.IP) {
|
||||
t.Fatal("Add update not received as expected")
|
||||
}
|
||||
if err := RouteDel(&route); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !expectRouteUpdate(ch, unix.RTM_DELROUTE, dst.IP) {
|
||||
if !expectRouteUpdate(ch, unix.RTM_DELROUTE, 0, dst.IP) {
|
||||
t.Fatal("Del update not received as expected")
|
||||
}
|
||||
}
|
||||
|
@ -649,7 +650,7 @@ func TestRouteSubscribeWithOptions(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !expectRouteUpdate(ch, unix.RTM_NEWROUTE, dst.IP) {
|
||||
if !expectRouteUpdate(ch, unix.RTM_NEWROUTE, unix.NLM_F_EXCL|unix.NLM_F_CREATE, dst.IP) {
|
||||
t.Fatal("Add update not received as expected")
|
||||
}
|
||||
}
|
||||
|
@ -701,13 +702,13 @@ func TestRouteSubscribeAt(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !expectRouteUpdate(ch, unix.RTM_NEWROUTE, dst.IP) {
|
||||
if !expectRouteUpdate(ch, unix.RTM_NEWROUTE, unix.NLM_F_EXCL|unix.NLM_F_CREATE, dst.IP) {
|
||||
t.Fatal("Add update not received as expected")
|
||||
}
|
||||
if err := nh.RouteDel(&route); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !expectRouteUpdate(ch, unix.RTM_DELROUTE, dst.IP) {
|
||||
if !expectRouteUpdate(ch, unix.RTM_DELROUTE, 0, dst.IP) {
|
||||
t.Fatal("Del update not received as expected")
|
||||
}
|
||||
}
|
||||
|
@ -762,7 +763,7 @@ func TestRouteSubscribeListExisting(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !expectRouteUpdate(ch, unix.RTM_NEWROUTE, dst10.IP) {
|
||||
if !expectRouteUpdate(ch, unix.RTM_NEWROUTE, 0, dst10.IP) {
|
||||
t.Fatal("Existing add update not received as expected")
|
||||
}
|
||||
|
||||
|
@ -777,19 +778,19 @@ func TestRouteSubscribeListExisting(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !expectRouteUpdate(ch, unix.RTM_NEWROUTE, dst.IP) {
|
||||
if !expectRouteUpdate(ch, unix.RTM_NEWROUTE, unix.NLM_F_EXCL|unix.NLM_F_CREATE, dst.IP) {
|
||||
t.Fatal("Add update not received as expected")
|
||||
}
|
||||
if err := nh.RouteDel(&route); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !expectRouteUpdate(ch, unix.RTM_DELROUTE, dst.IP) {
|
||||
if !expectRouteUpdate(ch, unix.RTM_DELROUTE, 0, dst.IP) {
|
||||
t.Fatal("Del update not received as expected")
|
||||
}
|
||||
if err := nh.RouteDel(&route10); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !expectRouteUpdate(ch, unix.RTM_DELROUTE, dst10.IP) {
|
||||
if !expectRouteUpdate(ch, unix.RTM_DELROUTE, 0, dst10.IP) {
|
||||
t.Fatal("Del update not received as expected")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue