Skip to content

Commit 5b4237b

Browse files
joestringerdavem330
authored andcommitted
openvswitch: Refactor ovs_nla_fill_match().
Refactor the ovs_nla_fill_match() function into separate netlink serialization functions ovs_nla_put_{unmasked_key,mask}(). Modify ovs_nla_put_flow() to handle attribute nesting and expose the 'is_mask' parameter - all callers need to nest the flow, and callers have better knowledge about whether it is serializing a mask or not. Signed-off-by: Joe Stringer <joestringer@nicira.com> Acked-by: Pravin B Shelar <pshelar@nicira.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 707d79e commit 5b4237b

File tree

3 files changed

+46
-40
lines changed

3 files changed

+46
-40
lines changed

net/openvswitch/datapath.c

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,8 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
461461
0, upcall_info->cmd);
462462
upcall->dp_ifindex = dp_ifindex;
463463

464-
nla = nla_nest_start(user_skb, OVS_PACKET_ATTR_KEY);
465-
err = ovs_nla_put_flow(key, key, user_skb);
464+
err = ovs_nla_put_key(key, key, OVS_PACKET_ATTR_KEY, false, user_skb);
466465
BUG_ON(err);
467-
nla_nest_end(user_skb, nla);
468466

469467
if (upcall_info->userdata)
470468
__nla_put(user_skb, OVS_PACKET_ATTR_USERDATA,
@@ -675,37 +673,6 @@ static size_t ovs_flow_cmd_msg_size(const struct sw_flow_actions *acts)
675673
+ nla_total_size(acts->actions_len); /* OVS_FLOW_ATTR_ACTIONS */
676674
}
677675

678-
/* Called with ovs_mutex or RCU read lock. */
679-
static int ovs_flow_cmd_fill_match(const struct sw_flow *flow,
680-
struct sk_buff *skb)
681-
{
682-
struct nlattr *nla;
683-
int err;
684-
685-
/* Fill flow key. */
686-
nla = nla_nest_start(skb, OVS_FLOW_ATTR_KEY);
687-
if (!nla)
688-
return -EMSGSIZE;
689-
690-
err = ovs_nla_put_flow(&flow->unmasked_key, &flow->unmasked_key, skb);
691-
if (err)
692-
return err;
693-
694-
nla_nest_end(skb, nla);
695-
696-
/* Fill flow mask. */
697-
nla = nla_nest_start(skb, OVS_FLOW_ATTR_MASK);
698-
if (!nla)
699-
return -EMSGSIZE;
700-
701-
err = ovs_nla_put_flow(&flow->key, &flow->mask->key, skb);
702-
if (err)
703-
return err;
704-
705-
nla_nest_end(skb, nla);
706-
return 0;
707-
}
708-
709676
/* Called with ovs_mutex or RCU read lock. */
710677
static int ovs_flow_cmd_fill_stats(const struct sw_flow *flow,
711678
struct sk_buff *skb)
@@ -787,7 +754,11 @@ static int ovs_flow_cmd_fill_info(const struct sw_flow *flow, int dp_ifindex,
787754

788755
ovs_header->dp_ifindex = dp_ifindex;
789756

790-
err = ovs_flow_cmd_fill_match(flow, skb);
757+
err = ovs_nla_put_unmasked_key(flow, skb);
758+
if (err)
759+
goto error;
760+
761+
err = ovs_nla_put_mask(flow, skb);
791762
if (err)
792763
goto error;
793764

net/openvswitch/flow_netlink.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,12 +1216,12 @@ int ovs_nla_get_flow_metadata(const struct nlattr *attr,
12161216
return metadata_from_nlattrs(&match, &attrs, a, false, log);
12171217
}
12181218

1219-
int ovs_nla_put_flow(const struct sw_flow_key *swkey,
1220-
const struct sw_flow_key *output, struct sk_buff *skb)
1219+
static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
1220+
const struct sw_flow_key *output, bool is_mask,
1221+
struct sk_buff *skb)
12211222
{
12221223
struct ovs_key_ethernet *eth_key;
12231224
struct nlattr *nla, *encap;
1224-
bool is_mask = (swkey != output);
12251225

12261226
if (nla_put_u32(skb, OVS_KEY_ATTR_RECIRC_ID, output->recirc_id))
12271227
goto nla_put_failure;
@@ -1431,6 +1431,38 @@ int ovs_nla_put_flow(const struct sw_flow_key *swkey,
14311431
return -EMSGSIZE;
14321432
}
14331433

1434+
int ovs_nla_put_key(const struct sw_flow_key *swkey,
1435+
const struct sw_flow_key *output, int attr, bool is_mask,
1436+
struct sk_buff *skb)
1437+
{
1438+
int err;
1439+
struct nlattr *nla;
1440+
1441+
nla = nla_nest_start(skb, attr);
1442+
if (!nla)
1443+
return -EMSGSIZE;
1444+
err = __ovs_nla_put_key(swkey, output, is_mask, skb);
1445+
if (err)
1446+
return err;
1447+
nla_nest_end(skb, nla);
1448+
1449+
return 0;
1450+
}
1451+
1452+
/* Called with ovs_mutex or RCU read lock. */
1453+
int ovs_nla_put_unmasked_key(const struct sw_flow *flow, struct sk_buff *skb)
1454+
{
1455+
return ovs_nla_put_key(&flow->unmasked_key, &flow->unmasked_key,
1456+
OVS_FLOW_ATTR_KEY, false, skb);
1457+
}
1458+
1459+
/* Called with ovs_mutex or RCU read lock. */
1460+
int ovs_nla_put_mask(const struct sw_flow *flow, struct sk_buff *skb)
1461+
{
1462+
return ovs_nla_put_key(&flow->key, &flow->mask->key,
1463+
OVS_FLOW_ATTR_MASK, true, skb);
1464+
}
1465+
14341466
#define MAX_ACTIONS_BUFSIZE (32 * 1024)
14351467

14361468
static struct sw_flow_actions *nla_alloc_flow_actions(int size, bool log)

net/openvswitch/flow_netlink.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ size_t ovs_key_attr_size(void);
4343
void ovs_match_init(struct sw_flow_match *match,
4444
struct sw_flow_key *key, struct sw_flow_mask *mask);
4545

46-
int ovs_nla_put_flow(const struct sw_flow_key *,
47-
const struct sw_flow_key *, struct sk_buff *);
46+
int ovs_nla_put_key(const struct sw_flow_key *, const struct sw_flow_key *,
47+
int attr, bool is_mask, struct sk_buff *);
4848
int ovs_nla_get_flow_metadata(const struct nlattr *, struct sw_flow_key *,
4949
bool log);
5050

51+
int ovs_nla_put_unmasked_key(const struct sw_flow *flow, struct sk_buff *skb);
52+
int ovs_nla_put_mask(const struct sw_flow *flow, struct sk_buff *skb);
53+
5154
int ovs_nla_get_match(struct sw_flow_match *, const struct nlattr *key,
5255
const struct nlattr *mask, bool log);
5356
int ovs_nla_put_egress_tunnel_key(struct sk_buff *,

0 commit comments

Comments
 (0)