diff options
author | Jiri Pirko <jpirko@redhat.com> | 2012-04-10 01:15:43 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-04-11 10:03:51 -0400 |
commit | 14f066bab19946545130a7379f420af860a02ae8 (patch) | |
tree | 7d8bac0fb889e2c7bee2c129d540ce6e6cacb340 /drivers/net/team/team.c | |
parent | 80f7c6683fe0e891ef1db7c967d538b5fdddd22c (diff) |
team: add bool option type
Add another (hopefully last) option type. Use NLA_FLAG to implement
that.
Signed-off-by: Jiri Pirko <jpirko@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/team/team.c')
-rw-r--r-- | drivers/net/team/team.c | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c index eaf8441753ce..2645fae26d6f 100644 --- a/drivers/net/team/team.c +++ b/drivers/net/team/team.c | |||
@@ -1463,6 +1463,16 @@ static int team_nl_fill_options_get(struct sk_buff *skb, | |||
1463 | ctx.data.bin_val.len, ctx.data.bin_val.ptr)) | 1463 | ctx.data.bin_val.len, ctx.data.bin_val.ptr)) |
1464 | goto nla_put_failure; | 1464 | goto nla_put_failure; |
1465 | break; | 1465 | break; |
1466 | case TEAM_OPTION_TYPE_BOOL: | ||
1467 | if (nla_put_u8(skb, TEAM_ATTR_OPTION_TYPE, NLA_FLAG)) | ||
1468 | goto nla_put_failure; | ||
1469 | err = team_option_get(team, opt_inst, &ctx); | ||
1470 | if (err) | ||
1471 | goto errout; | ||
1472 | if (ctx.data.bool_val && | ||
1473 | nla_put_flag(skb, TEAM_ATTR_OPTION_DATA)) | ||
1474 | goto nla_put_failure; | ||
1475 | break; | ||
1466 | default: | 1476 | default: |
1467 | BUG(); | 1477 | BUG(); |
1468 | } | 1478 | } |
@@ -1524,6 +1534,7 @@ static int team_nl_cmd_options_set(struct sk_buff *skb, struct genl_info *info) | |||
1524 | nla_for_each_nested(nl_option, info->attrs[TEAM_ATTR_LIST_OPTION], i) { | 1534 | nla_for_each_nested(nl_option, info->attrs[TEAM_ATTR_LIST_OPTION], i) { |
1525 | struct nlattr *opt_attrs[TEAM_ATTR_OPTION_MAX + 1]; | 1535 | struct nlattr *opt_attrs[TEAM_ATTR_OPTION_MAX + 1]; |
1526 | struct nlattr *attr_port_ifindex; | 1536 | struct nlattr *attr_port_ifindex; |
1537 | struct nlattr *attr_data; | ||
1527 | enum team_option_type opt_type; | 1538 | enum team_option_type opt_type; |
1528 | int opt_port_ifindex = 0; /* != 0 for per-port options */ | 1539 | int opt_port_ifindex = 0; /* != 0 for per-port options */ |
1529 | struct team_option_inst *opt_inst; | 1540 | struct team_option_inst *opt_inst; |
@@ -1539,8 +1550,7 @@ static int team_nl_cmd_options_set(struct sk_buff *skb, struct genl_info *info) | |||
1539 | if (err) | 1550 | if (err) |
1540 | goto team_put; | 1551 | goto team_put; |
1541 | if (!opt_attrs[TEAM_ATTR_OPTION_NAME] || | 1552 | if (!opt_attrs[TEAM_ATTR_OPTION_NAME] || |
1542 | !opt_attrs[TEAM_ATTR_OPTION_TYPE] || | 1553 | !opt_attrs[TEAM_ATTR_OPTION_TYPE]) { |
1543 | !opt_attrs[TEAM_ATTR_OPTION_DATA]) { | ||
1544 | err = -EINVAL; | 1554 | err = -EINVAL; |
1545 | goto team_put; | 1555 | goto team_put; |
1546 | } | 1556 | } |
@@ -1554,10 +1564,19 @@ static int team_nl_cmd_options_set(struct sk_buff *skb, struct genl_info *info) | |||
1554 | case NLA_BINARY: | 1564 | case NLA_BINARY: |
1555 | opt_type = TEAM_OPTION_TYPE_BINARY; | 1565 | opt_type = TEAM_OPTION_TYPE_BINARY; |
1556 | break; | 1566 | break; |
1567 | case NLA_FLAG: | ||
1568 | opt_type = TEAM_OPTION_TYPE_BOOL; | ||
1569 | break; | ||
1557 | default: | 1570 | default: |
1558 | goto team_put; | 1571 | goto team_put; |
1559 | } | 1572 | } |
1560 | 1573 | ||
1574 | attr_data = opt_attrs[TEAM_ATTR_OPTION_DATA]; | ||
1575 | if (opt_type != TEAM_OPTION_TYPE_BOOL && !attr_data) { | ||
1576 | err = -EINVAL; | ||
1577 | goto team_put; | ||
1578 | } | ||
1579 | |||
1561 | opt_name = nla_data(opt_attrs[TEAM_ATTR_OPTION_NAME]); | 1580 | opt_name = nla_data(opt_attrs[TEAM_ATTR_OPTION_NAME]); |
1562 | attr_port_ifindex = opt_attrs[TEAM_ATTR_OPTION_PORT_IFINDEX]; | 1581 | attr_port_ifindex = opt_attrs[TEAM_ATTR_OPTION_PORT_IFINDEX]; |
1563 | if (attr_port_ifindex) | 1582 | if (attr_port_ifindex) |
@@ -1565,9 +1584,7 @@ static int team_nl_cmd_options_set(struct sk_buff *skb, struct genl_info *info) | |||
1565 | 1584 | ||
1566 | list_for_each_entry(opt_inst, &team->option_inst_list, list) { | 1585 | list_for_each_entry(opt_inst, &team->option_inst_list, list) { |
1567 | struct team_option *option = opt_inst->option; | 1586 | struct team_option *option = opt_inst->option; |
1568 | struct nlattr *opt_data_attr; | ||
1569 | struct team_gsetter_ctx ctx; | 1587 | struct team_gsetter_ctx ctx; |
1570 | int data_len; | ||
1571 | int tmp_ifindex; | 1588 | int tmp_ifindex; |
1572 | 1589 | ||
1573 | tmp_ifindex = opt_inst->port ? | 1590 | tmp_ifindex = opt_inst->port ? |
@@ -1577,23 +1594,24 @@ static int team_nl_cmd_options_set(struct sk_buff *skb, struct genl_info *info) | |||
1577 | tmp_ifindex != opt_port_ifindex) | 1594 | tmp_ifindex != opt_port_ifindex) |
1578 | continue; | 1595 | continue; |
1579 | opt_found = true; | 1596 | opt_found = true; |
1580 | opt_data_attr = opt_attrs[TEAM_ATTR_OPTION_DATA]; | ||
1581 | data_len = nla_len(opt_data_attr); | ||
1582 | ctx.port = opt_inst->port; | 1597 | ctx.port = opt_inst->port; |
1583 | switch (opt_type) { | 1598 | switch (opt_type) { |
1584 | case TEAM_OPTION_TYPE_U32: | 1599 | case TEAM_OPTION_TYPE_U32: |
1585 | ctx.data.u32_val = nla_get_u32(opt_data_attr); | 1600 | ctx.data.u32_val = nla_get_u32(attr_data); |
1586 | break; | 1601 | break; |
1587 | case TEAM_OPTION_TYPE_STRING: | 1602 | case TEAM_OPTION_TYPE_STRING: |
1588 | if (data_len > TEAM_STRING_MAX_LEN) { | 1603 | if (nla_len(attr_data) > TEAM_STRING_MAX_LEN) { |
1589 | err = -EINVAL; | 1604 | err = -EINVAL; |
1590 | goto team_put; | 1605 | goto team_put; |
1591 | } | 1606 | } |
1592 | ctx.data.str_val = nla_data(opt_data_attr); | 1607 | ctx.data.str_val = nla_data(attr_data); |
1593 | break; | 1608 | break; |
1594 | case TEAM_OPTION_TYPE_BINARY: | 1609 | case TEAM_OPTION_TYPE_BINARY: |
1595 | ctx.data.bin_val.len = data_len; | 1610 | ctx.data.bin_val.len = nla_len(attr_data); |
1596 | ctx.data.bin_val.ptr = nla_data(opt_data_attr); | 1611 | ctx.data.bin_val.ptr = nla_data(attr_data); |
1612 | break; | ||
1613 | case TEAM_OPTION_TYPE_BOOL: | ||
1614 | ctx.data.bool_val = attr_data ? true : false; | ||
1597 | break; | 1615 | break; |
1598 | default: | 1616 | default: |
1599 | BUG(); | 1617 | BUG(); |