Commit 7d4caf54 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller
Browse files

netlink: specs: add support for auto-sized scalars



Support uint / sint types in specs and YNL.

Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Acked-by: default avatarNicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 374d345d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -149,7 +149,8 @@ properties:
              name:
                type: string
              type: &attr-type
                enum: [ unused, pad, flag, binary, u8, u16, u32, u64, s32, s64,
                enum: [ unused, pad, flag, binary,
                        uint, sint, u8, u16, u32, u64, s32, s64,
                        string, nest, array-nest, nest-type-value ]
              doc:
                description: Documentation of the attribute.
+2 −1
Original line number Diff line number Diff line
@@ -192,7 +192,8 @@ properties:
                type: string
              type: &attr-type
                description: The netlink attribute type
                enum: [ unused, pad, flag, binary, u8, u16, u32, u64, s32, s64,
                enum: [ unused, pad, flag, binary,
                        uint, sint, u8, u16, u32, u64, s32, s64,
                        string, nest, array-nest, nest-type-value ]
              doc:
                description: Documentation of the attribute.
+2 −1
Original line number Diff line number Diff line
@@ -122,7 +122,8 @@ properties:
              name:
                type: string
              type: &attr-type
                enum: [ unused, pad, flag, binary, u8, u16, u32, u64, s32, s64,
                enum: [ unused, pad, flag, binary,
                        uint, sint, u8, u16, u32, u64, s32, s64,
                        string, nest, array-nest, nest-type-value ]
              doc:
                description: Documentation of the attribute.
+6 −0
Original line number Diff line number Diff line
@@ -149,6 +149,7 @@ class SpecAttr(SpecElement):
    Represents a single attribute type within an attr space.

    Attributes:
        type          string, attribute type
        value         numerical ID when serialized
        attr_set      Attribute Set containing this attr
        is_multi      bool, attr may repeat multiple times
@@ -157,10 +158,13 @@ class SpecAttr(SpecElement):
        len           integer, optional byte length of binary types
        display_hint  string, hint to help choose format specifier
                      when displaying the value

        is_auto_scalar bool, attr is a variable-size scalar
    """
    def __init__(self, family, attr_set, yaml, value):
        super().__init__(family, yaml)

        self.type = yaml['type']
        self.value = value
        self.attr_set = attr_set
        self.is_multi = yaml.get('multi-attr', False)
@@ -170,6 +174,8 @@ class SpecAttr(SpecElement):
        self.len = yaml.get('len')
        self.display_hint = yaml.get('display-hint')

        self.is_auto_scalar = self.type == "sint" or self.type == "uint"


class SpecAttrSet(SpecElement):
    """ Netlink Attribute Set class.
+6 −0
Original line number Diff line number Diff line
@@ -352,6 +352,12 @@ int ynl_attr_validate(struct ynl_parse_arg *yarg, const struct nlattr *attr)
		yerr(yarg->ys, YNL_ERROR_ATTR_INVALID,
		     "Invalid attribute (u64 %s)", policy->name);
		return -1;
	case YNL_PT_UINT:
		if (len == sizeof(__u32) || len == sizeof(__u64))
			break;
		yerr(yarg->ys, YNL_ERROR_ATTR_INVALID,
		     "Invalid attribute (uint %s)", policy->name);
		return -1;
	case YNL_PT_FLAG:
		/* Let flags grow into real attrs, why not.. */
		break;
Loading