diff options
Diffstat (limited to 'include/net/netlink.h')
-rw-r--r-- | include/net/netlink.h | 169 |
1 files changed, 100 insertions, 69 deletions
diff --git a/include/net/netlink.h b/include/net/netlink.h index f394fe5d7641..785f37a3b44e 100644 --- a/include/net/netlink.h +++ b/include/net/netlink.h | |||
@@ -102,20 +102,6 @@ | |||
102 | * nla_put_flag(skb, type) add flag attribute to skb | 102 | * nla_put_flag(skb, type) add flag attribute to skb |
103 | * nla_put_msecs(skb, type, jiffies) add msecs attribute to skb | 103 | * nla_put_msecs(skb, type, jiffies) add msecs attribute to skb |
104 | * | 104 | * |
105 | * Exceptions Based Attribute Construction: | ||
106 | * NLA_PUT(skb, type, len, data) add attribute to skb | ||
107 | * NLA_PUT_U8(skb, type, value) add u8 attribute to skb | ||
108 | * NLA_PUT_U16(skb, type, value) add u16 attribute to skb | ||
109 | * NLA_PUT_U32(skb, type, value) add u32 attribute to skb | ||
110 | * NLA_PUT_U64(skb, type, value) add u64 attribute to skb | ||
111 | * NLA_PUT_STRING(skb, type, str) add string attribute to skb | ||
112 | * NLA_PUT_FLAG(skb, type) add flag attribute to skb | ||
113 | * NLA_PUT_MSECS(skb, type, jiffies) add msecs attribute to skb | ||
114 | * | ||
115 | * The meaning of these functions is equal to their lower case | ||
116 | * variants but they jump to the label nla_put_failure in case | ||
117 | * of a failure. | ||
118 | * | ||
119 | * Nested Attributes Construction: | 105 | * Nested Attributes Construction: |
120 | * nla_nest_start(skb, type) start a nested attribute | 106 | * nla_nest_start(skb, type) start a nested attribute |
121 | * nla_nest_end(skb, nla) finalize a nested attribute | 107 | * nla_nest_end(skb, nla) finalize a nested attribute |
@@ -772,6 +758,39 @@ static inline int nla_put_u16(struct sk_buff *skb, int attrtype, u16 value) | |||
772 | } | 758 | } |
773 | 759 | ||
774 | /** | 760 | /** |
761 | * nla_put_be16 - Add a __be16 netlink attribute to a socket buffer | ||
762 | * @skb: socket buffer to add attribute to | ||
763 | * @attrtype: attribute type | ||
764 | * @value: numeric value | ||
765 | */ | ||
766 | static inline int nla_put_be16(struct sk_buff *skb, int attrtype, __be16 value) | ||
767 | { | ||
768 | return nla_put(skb, attrtype, sizeof(__be16), &value); | ||
769 | } | ||
770 | |||
771 | /** | ||
772 | * nla_put_net16 - Add 16-bit network byte order netlink attribute to a socket buffer | ||
773 | * @skb: socket buffer to add attribute to | ||
774 | * @attrtype: attribute type | ||
775 | * @value: numeric value | ||
776 | */ | ||
777 | static inline int nla_put_net16(struct sk_buff *skb, int attrtype, __be16 value) | ||
778 | { | ||
779 | return nla_put_be16(skb, attrtype | NLA_F_NET_BYTEORDER, value); | ||
780 | } | ||
781 | |||
782 | /** | ||
783 | * nla_put_le16 - Add a __le16 netlink attribute to a socket buffer | ||
784 | * @skb: socket buffer to add attribute to | ||
785 | * @attrtype: attribute type | ||
786 | * @value: numeric value | ||
787 | */ | ||
788 | static inline int nla_put_le16(struct sk_buff *skb, int attrtype, __le16 value) | ||
789 | { | ||
790 | return nla_put(skb, attrtype, sizeof(__le16), &value); | ||
791 | } | ||
792 | |||
793 | /** | ||
775 | * nla_put_u32 - Add a u32 netlink attribute to a socket buffer | 794 | * nla_put_u32 - Add a u32 netlink attribute to a socket buffer |
776 | * @skb: socket buffer to add attribute to | 795 | * @skb: socket buffer to add attribute to |
777 | * @attrtype: attribute type | 796 | * @attrtype: attribute type |
@@ -783,7 +802,40 @@ static inline int nla_put_u32(struct sk_buff *skb, int attrtype, u32 value) | |||
783 | } | 802 | } |
784 | 803 | ||
785 | /** | 804 | /** |
786 | * nla_put_64 - Add a u64 netlink attribute to a socket buffer | 805 | * nla_put_be32 - Add a __be32 netlink attribute to a socket buffer |
806 | * @skb: socket buffer to add attribute to | ||
807 | * @attrtype: attribute type | ||
808 | * @value: numeric value | ||
809 | */ | ||
810 | static inline int nla_put_be32(struct sk_buff *skb, int attrtype, __be32 value) | ||
811 | { | ||
812 | return nla_put(skb, attrtype, sizeof(__be32), &value); | ||
813 | } | ||
814 | |||
815 | /** | ||
816 | * nla_put_net32 - Add 32-bit network byte order netlink attribute to a socket buffer | ||
817 | * @skb: socket buffer to add attribute to | ||
818 | * @attrtype: attribute type | ||
819 | * @value: numeric value | ||
820 | */ | ||
821 | static inline int nla_put_net32(struct sk_buff *skb, int attrtype, __be32 value) | ||
822 | { | ||
823 | return nla_put_be32(skb, attrtype | NLA_F_NET_BYTEORDER, value); | ||
824 | } | ||
825 | |||
826 | /** | ||
827 | * nla_put_le32 - Add a __le32 netlink attribute to a socket buffer | ||
828 | * @skb: socket buffer to add attribute to | ||
829 | * @attrtype: attribute type | ||
830 | * @value: numeric value | ||
831 | */ | ||
832 | static inline int nla_put_le32(struct sk_buff *skb, int attrtype, __le32 value) | ||
833 | { | ||
834 | return nla_put(skb, attrtype, sizeof(__le32), &value); | ||
835 | } | ||
836 | |||
837 | /** | ||
838 | * nla_put_u64 - Add a u64 netlink attribute to a socket buffer | ||
787 | * @skb: socket buffer to add attribute to | 839 | * @skb: socket buffer to add attribute to |
788 | * @attrtype: attribute type | 840 | * @attrtype: attribute type |
789 | * @value: numeric value | 841 | * @value: numeric value |
@@ -794,6 +846,39 @@ static inline int nla_put_u64(struct sk_buff *skb, int attrtype, u64 value) | |||
794 | } | 846 | } |
795 | 847 | ||
796 | /** | 848 | /** |
849 | * nla_put_be64 - Add a __be64 netlink attribute to a socket buffer | ||
850 | * @skb: socket buffer to add attribute to | ||
851 | * @attrtype: attribute type | ||
852 | * @value: numeric value | ||
853 | */ | ||
854 | static inline int nla_put_be64(struct sk_buff *skb, int attrtype, __be64 value) | ||
855 | { | ||
856 | return nla_put(skb, attrtype, sizeof(__be64), &value); | ||
857 | } | ||
858 | |||
859 | /** | ||
860 | * nla_put_net64 - Add 64-bit network byte order netlink attribute to a socket buffer | ||
861 | * @skb: socket buffer to add attribute to | ||
862 | * @attrtype: attribute type | ||
863 | * @value: numeric value | ||
864 | */ | ||
865 | static inline int nla_put_net64(struct sk_buff *skb, int attrtype, __be64 value) | ||
866 | { | ||
867 | return nla_put_be64(skb, attrtype | NLA_F_NET_BYTEORDER, value); | ||
868 | } | ||
869 | |||
870 | /** | ||
871 | * nla_put_le64 - Add a __le64 netlink attribute to a socket buffer | ||
872 | * @skb: socket buffer to add attribute to | ||
873 | * @attrtype: attribute type | ||
874 | * @value: numeric value | ||
875 | */ | ||
876 | static inline int nla_put_le64(struct sk_buff *skb, int attrtype, __le64 value) | ||
877 | { | ||
878 | return nla_put(skb, attrtype, sizeof(__le64), &value); | ||
879 | } | ||
880 | |||
881 | /** | ||
797 | * nla_put_string - Add a string netlink attribute to a socket buffer | 882 | * nla_put_string - Add a string netlink attribute to a socket buffer |
798 | * @skb: socket buffer to add attribute to | 883 | * @skb: socket buffer to add attribute to |
799 | * @attrtype: attribute type | 884 | * @attrtype: attribute type |
@@ -828,60 +913,6 @@ static inline int nla_put_msecs(struct sk_buff *skb, int attrtype, | |||
828 | return nla_put(skb, attrtype, sizeof(u64), &tmp); | 913 | return nla_put(skb, attrtype, sizeof(u64), &tmp); |
829 | } | 914 | } |
830 | 915 | ||
831 | #define NLA_PUT(skb, attrtype, attrlen, data) \ | ||
832 | do { \ | ||
833 | if (unlikely(nla_put(skb, attrtype, attrlen, data) < 0)) \ | ||
834 | goto nla_put_failure; \ | ||
835 | } while(0) | ||
836 | |||
837 | #define NLA_PUT_TYPE(skb, type, attrtype, value) \ | ||
838 | do { \ | ||
839 | type __tmp = value; \ | ||
840 | NLA_PUT(skb, attrtype, sizeof(type), &__tmp); \ | ||
841 | } while(0) | ||
842 | |||
843 | #define NLA_PUT_U8(skb, attrtype, value) \ | ||
844 | NLA_PUT_TYPE(skb, u8, attrtype, value) | ||
845 | |||
846 | #define NLA_PUT_U16(skb, attrtype, value) \ | ||
847 | NLA_PUT_TYPE(skb, u16, attrtype, value) | ||
848 | |||
849 | #define NLA_PUT_LE16(skb, attrtype, value) \ | ||
850 | NLA_PUT_TYPE(skb, __le16, attrtype, value) | ||
851 | |||
852 | #define NLA_PUT_BE16(skb, attrtype, value) \ | ||
853 | NLA_PUT_TYPE(skb, __be16, attrtype, value) | ||
854 | |||
855 | #define NLA_PUT_NET16(skb, attrtype, value) \ | ||
856 | NLA_PUT_BE16(skb, attrtype | NLA_F_NET_BYTEORDER, value) | ||
857 | |||
858 | #define NLA_PUT_U32(skb, attrtype, value) \ | ||
859 | NLA_PUT_TYPE(skb, u32, attrtype, value) | ||
860 | |||
861 | #define NLA_PUT_BE32(skb, attrtype, value) \ | ||
862 | NLA_PUT_TYPE(skb, __be32, attrtype, value) | ||
863 | |||
864 | #define NLA_PUT_NET32(skb, attrtype, value) \ | ||
865 | NLA_PUT_BE32(skb, attrtype | NLA_F_NET_BYTEORDER, value) | ||
866 | |||
867 | #define NLA_PUT_U64(skb, attrtype, value) \ | ||
868 | NLA_PUT_TYPE(skb, u64, attrtype, value) | ||
869 | |||
870 | #define NLA_PUT_BE64(skb, attrtype, value) \ | ||
871 | NLA_PUT_TYPE(skb, __be64, attrtype, value) | ||
872 | |||
873 | #define NLA_PUT_NET64(skb, attrtype, value) \ | ||
874 | NLA_PUT_BE64(skb, attrtype | NLA_F_NET_BYTEORDER, value) | ||
875 | |||
876 | #define NLA_PUT_STRING(skb, attrtype, value) \ | ||
877 | NLA_PUT(skb, attrtype, strlen(value) + 1, value) | ||
878 | |||
879 | #define NLA_PUT_FLAG(skb, attrtype) \ | ||
880 | NLA_PUT(skb, attrtype, 0, NULL) | ||
881 | |||
882 | #define NLA_PUT_MSECS(skb, attrtype, jiffies) \ | ||
883 | NLA_PUT_U64(skb, attrtype, jiffies_to_msecs(jiffies)) | ||
884 | |||
885 | /** | 916 | /** |
886 | * nla_get_u32 - return payload of u32 attribute | 917 | * nla_get_u32 - return payload of u32 attribute |
887 | * @nla: u32 netlink attribute | 918 | * @nla: u32 netlink attribute |