Skip to content

Commit 8ce3b42

Browse files
ovsnl: only fail if no known families are found (#88)
Before this commit the ovnl client logic was such that it needs to be kept in lock-step synchronization with a particular version of the netlink interface. This is too fragile, as each new update requires touching this logic, which in turn makes it non-backward compatible. This commit flips the logic on its head and instead makes the client complains only if no 'known' families are found. This makes the init logic future proof and backward compatible.
1 parent b8197d4 commit 8ce3b42

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed

ovsnl/client.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,32 +80,25 @@ func (c *Client) Close() error {
8080

8181
// init initializes the generic netlink family service of Client.
8282
func (c *Client) init(families []genetlink.Family) error {
83-
// Assume 5 families present.
8483
var gotf int
85-
const wantf = 5
8684

8785
for _, f := range families {
8886
// Ignore any families without the OVS prefix.
8987
if !strings.HasPrefix(f.Name, "ovs_") {
9088
continue
9189
}
92-
93-
gotf++
90+
// Ignore any families that might be unknown.
9491
if err := c.initFamily(f); err != nil {
95-
return err
92+
continue
9693
}
94+
gotf++
9795
}
9896

99-
// No families; return error for os.IsNotExist check.
97+
// No known families; return error for os.IsNotExist check.
10098
if gotf == 0 {
10199
return os.ErrNotExist
102100
}
103101

104-
if gotf != wantf {
105-
return fmt.Errorf("expected %d OVS generic netlink families, but found %d",
106-
wantf, gotf)
107-
}
108-
109102
return nil
110103
}
111104

@@ -118,12 +111,10 @@ func (c *Client) initFamily(f genetlink.Family) error {
118111
c: c,
119112
}
120113
return nil
121-
case ovsh.FlowFamily, ovsh.PacketFamily, ovsh.VportFamily, ovsh.MeterFamily:
122-
// TODO(mdlayher): populate.
123-
return nil
114+
default:
115+
// Unknown OVS netlink family, nothing we can do.
116+
return fmt.Errorf("unknown OVS generic netlink family: %q", f.Name)
124117
}
125-
126-
return fmt.Errorf("unrecognized OVS generic netlink family: %q", f.Name)
127118
}
128119

129120
// headerBytes converts an ovsh.Header into a byte slice.

ovsnl/client_linux_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestClientNoFamiliesIsNotExist(t *testing.T) {
4646
t.Logf("OK error: %v", err)
4747
}
4848

49-
func TestClientInvalidFamily(t *testing.T) {
49+
func TestClientUnknownFamilies(t *testing.T) {
5050
conn := genltest.Dial(func(greq genetlink.Message, nreq netlink.Message) ([]genetlink.Message, error) {
5151
return familyMessages([]string{
5252
"ovs_foo",
@@ -61,12 +61,10 @@ func TestClientInvalidFamily(t *testing.T) {
6161
t.Logf("OK error: %v", err)
6262
}
6363

64-
func TestClientMissingFamilies(t *testing.T) {
64+
func TestClientNoFamilies(t *testing.T) {
6565
conn := genltest.Dial(func(greq genetlink.Message, nreq netlink.Message) ([]genetlink.Message, error) {
6666
// Too few OVS families.
67-
return familyMessages([]string{
68-
ovsh.DatapathFamily,
69-
}), nil
67+
return nil, nil
7068
})
7169

7270
_, err := newClient(conn)
@@ -77,14 +75,10 @@ func TestClientMissingFamilies(t *testing.T) {
7775
t.Logf("OK error: %v", err)
7876
}
7977

80-
func TestClientOK(t *testing.T) {
78+
func TestClientKnownFamilies(t *testing.T) {
8179
conn := genltest.Dial(func(greq genetlink.Message, nreq netlink.Message) ([]genetlink.Message, error) {
8280
return familyMessages([]string{
8381
ovsh.DatapathFamily,
84-
ovsh.FlowFamily,
85-
ovsh.PacketFamily,
86-
ovsh.VportFamily,
87-
ovsh.MeterFamily,
8882
}), nil
8983
})
9084

0 commit comments

Comments
 (0)