diff mbox

[RFC,14/29] net: vrf: Introduce vrf header file

Message ID 1423100070-31848-15-git-send-email-dsahern@gmail.com
State RFC, archived
Delegated to: David Miller
Headers show

Commit Message

David Ahern Feb. 5, 2015, 1:34 a.m. UTC
Defines for min and max vrf id and helpers for examining

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 include/net/vrf.h | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 include/net/vrf.h

Comments

Nicolas Dichtel Feb. 5, 2015, 1:44 p.m. UTC | #1
Le 05/02/2015 02:34, David Ahern a écrit :
> Defines for min and max vrf id and helpers for examining
>
> Signed-off-by: David Ahern <dsahern@gmail.com>
> ---
>   include/net/vrf.h | 36 ++++++++++++++++++++++++++++++++++++
>   1 file changed, 36 insertions(+)
>   create mode 100644 include/net/vrf.h
>
> diff --git a/include/net/vrf.h b/include/net/vrf.h
> new file mode 100644
> index 000000000000..67bc2e465661
> --- /dev/null
> +++ b/include/net/vrf.h
> @@ -0,0 +1,36 @@
> +#ifndef _VRF_H_
> +#define _VRF_H_
> +
> +#define VRF_BITS	12
> +#define VRF_MIN		1
> +#define VRF_MAX		((1 << VRF_BITS) - 1)
> +#define VRF_MASK	VRF_MAX
> +
> +#define VRF_DEFAULT	1
> +#define VRF_ANY		0xffff
It could be useful to expose this value to userland.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Ahern Feb. 6, 2015, 12:52 a.m. UTC | #2
On 2/5/15 6:44 AM, Nicolas Dichtel wrote:
> Le 05/02/2015 02:34, David Ahern a écrit :
>> Defines for min and max vrf id and helpers for examining
>>
>> Signed-off-by: David Ahern <dsahern@gmail.com>
>> ---
>>   include/net/vrf.h | 36 ++++++++++++++++++++++++++++++++++++
>>   1 file changed, 36 insertions(+)
>>   create mode 100644 include/net/vrf.h
>>
>> diff --git a/include/net/vrf.h b/include/net/vrf.h
>> new file mode 100644
>> index 000000000000..67bc2e465661
>> --- /dev/null
>> +++ b/include/net/vrf.h
>> @@ -0,0 +1,36 @@
>> +#ifndef _VRF_H_
>> +#define _VRF_H_
>> +
>> +#define VRF_BITS    12
>> +#define VRF_MIN        1
>> +#define VRF_MAX        ((1 << VRF_BITS) - 1)
>> +#define VRF_MASK    VRF_MAX
>> +
>> +#define VRF_DEFAULT    1
>> +#define VRF_ANY        0xffff
> It could be useful to expose this value to userland.

Maybe. I was thinking VRF_ANY should stay kernel side only and have a 
sockopt value of -1 mean VRF_ANY.

David
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Nicolas Dichtel Feb. 6, 2015, 8:53 a.m. UTC | #3
Le 06/02/2015 01:52, David Ahern a écrit :
> On 2/5/15 6:44 AM, Nicolas Dichtel wrote:
>> Le 05/02/2015 02:34, David Ahern a écrit :
[snip]
>>> +#define VRF_ANY        0xffff
>> It could be useful to expose this value to userland.
>
> Maybe. I was thinking VRF_ANY should stay kernel side only and have a sockopt
> value of -1 mean VRF_ANY.
Better to have a define instead of a magic value (-1) ;-)
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/net/vrf.h b/include/net/vrf.h
new file mode 100644
index 000000000000..67bc2e465661
--- /dev/null
+++ b/include/net/vrf.h
@@ -0,0 +1,36 @@ 
+#ifndef _VRF_H_
+#define _VRF_H_
+
+#define VRF_BITS	12
+#define VRF_MIN		1
+#define VRF_MAX		((1 << VRF_BITS) - 1)
+#define VRF_MASK	VRF_MAX
+
+#define VRF_DEFAULT	1
+#define VRF_ANY		0xffff
+
+static inline
+int vrf_eq(__u32 vrf1, __u32 vrf2)
+{
+	return vrf1 == vrf2;
+}
+
+static inline
+int vrf_eq_or_any(__u32 vrf1, __u32 vrf2)
+{
+	return vrf1 == vrf2 || vrf1 == VRF_ANY || vrf2 == VRF_ANY;
+}
+
+static inline int vrf_is_valid(__u32 vrf)
+{
+	if ((vrf < VRF_MIN || vrf > VRF_MAX) && vrf != VRF_ANY)
+		return 0;
+
+	return 1;
+}
+
+static inline int vrf_is_any(__u32 vrf)
+{
+	return vrf == VRF_ANY;
+}
+#endif