142
142
* nla_get_flag(nla) return 1 if flag is true
143
143
* nla_get_msecs(nla) get payload for a msecs attribute
144
144
*
145
+ * The same functions also exist with _default().
146
+ *
145
147
* Attribute Misc:
146
148
* nla_memcpy(dest, nla, count) copy attribute into memory
147
149
* nla_memcmp(nla, data, size) compare attribute with memory area
@@ -1695,6 +1697,20 @@ static inline u32 nla_get_u32(const struct nlattr *nla)
1695
1697
return * (u32 * ) nla_data (nla );
1696
1698
}
1697
1699
1700
+ /**
1701
+ * nla_get_u32_default - return payload of u32 attribute or default
1702
+ * @nla: u32 netlink attribute, may be %NULL
1703
+ * @defvalue: default value to use if @nla is %NULL
1704
+ *
1705
+ * Return: the value of the attribute, or the default value if not present
1706
+ */
1707
+ static inline u32 nla_get_u32_default (const struct nlattr * nla , u32 defvalue )
1708
+ {
1709
+ if (!nla )
1710
+ return defvalue ;
1711
+ return nla_get_u32 (nla );
1712
+ }
1713
+
1698
1714
/**
1699
1715
* nla_get_be32 - return payload of __be32 attribute
1700
1716
* @nla: __be32 netlink attribute
@@ -1704,6 +1720,21 @@ static inline __be32 nla_get_be32(const struct nlattr *nla)
1704
1720
return * (__be32 * ) nla_data (nla );
1705
1721
}
1706
1722
1723
+ /**
1724
+ * nla_get_be32_default - return payload of be32 attribute or default
1725
+ * @nla: __be32 netlink attribute, may be %NULL
1726
+ * @defvalue: default value to use if @nla is %NULL
1727
+ *
1728
+ * Return: the value of the attribute, or the default value if not present
1729
+ */
1730
+ static inline __be32 nla_get_be32_default (const struct nlattr * nla ,
1731
+ __be32 defvalue )
1732
+ {
1733
+ if (!nla )
1734
+ return defvalue ;
1735
+ return nla_get_be32 (nla );
1736
+ }
1737
+
1707
1738
/**
1708
1739
* nla_get_le32 - return payload of __le32 attribute
1709
1740
* @nla: __le32 netlink attribute
@@ -1713,6 +1744,21 @@ static inline __le32 nla_get_le32(const struct nlattr *nla)
1713
1744
return * (__le32 * ) nla_data (nla );
1714
1745
}
1715
1746
1747
+ /**
1748
+ * nla_get_le32_default - return payload of le32 attribute or default
1749
+ * @nla: __le32 netlink attribute, may be %NULL
1750
+ * @defvalue: default value to use if @nla is %NULL
1751
+ *
1752
+ * Return: the value of the attribute, or the default value if not present
1753
+ */
1754
+ static inline __le32 nla_get_le32_default (const struct nlattr * nla ,
1755
+ __le32 defvalue )
1756
+ {
1757
+ if (!nla )
1758
+ return defvalue ;
1759
+ return nla_get_le32 (nla );
1760
+ }
1761
+
1716
1762
/**
1717
1763
* nla_get_u16 - return payload of u16 attribute
1718
1764
* @nla: u16 netlink attribute
@@ -1722,6 +1768,20 @@ static inline u16 nla_get_u16(const struct nlattr *nla)
1722
1768
return * (u16 * ) nla_data (nla );
1723
1769
}
1724
1770
1771
+ /**
1772
+ * nla_get_u16_default - return payload of u16 attribute or default
1773
+ * @nla: u16 netlink attribute, may be %NULL
1774
+ * @defvalue: default value to use if @nla is %NULL
1775
+ *
1776
+ * Return: the value of the attribute, or the default value if not present
1777
+ */
1778
+ static inline u16 nla_get_u16_default (const struct nlattr * nla , u16 defvalue )
1779
+ {
1780
+ if (!nla )
1781
+ return defvalue ;
1782
+ return nla_get_u16 (nla );
1783
+ }
1784
+
1725
1785
/**
1726
1786
* nla_get_be16 - return payload of __be16 attribute
1727
1787
* @nla: __be16 netlink attribute
@@ -1731,6 +1791,21 @@ static inline __be16 nla_get_be16(const struct nlattr *nla)
1731
1791
return * (__be16 * ) nla_data (nla );
1732
1792
}
1733
1793
1794
+ /**
1795
+ * nla_get_be16_default - return payload of be16 attribute or default
1796
+ * @nla: __be16 netlink attribute, may be %NULL
1797
+ * @defvalue: default value to use if @nla is %NULL
1798
+ *
1799
+ * Return: the value of the attribute, or the default value if not present
1800
+ */
1801
+ static inline __be16 nla_get_be16_default (const struct nlattr * nla ,
1802
+ __be16 defvalue )
1803
+ {
1804
+ if (!nla )
1805
+ return defvalue ;
1806
+ return nla_get_be16 (nla );
1807
+ }
1808
+
1734
1809
/**
1735
1810
* nla_get_le16 - return payload of __le16 attribute
1736
1811
* @nla: __le16 netlink attribute
@@ -1740,6 +1815,21 @@ static inline __le16 nla_get_le16(const struct nlattr *nla)
1740
1815
return * (__le16 * ) nla_data (nla );
1741
1816
}
1742
1817
1818
+ /**
1819
+ * nla_get_le16_default - return payload of le16 attribute or default
1820
+ * @nla: __le16 netlink attribute, may be %NULL
1821
+ * @defvalue: default value to use if @nla is %NULL
1822
+ *
1823
+ * Return: the value of the attribute, or the default value if not present
1824
+ */
1825
+ static inline __le16 nla_get_le16_default (const struct nlattr * nla ,
1826
+ __le16 defvalue )
1827
+ {
1828
+ if (!nla )
1829
+ return defvalue ;
1830
+ return nla_get_le16 (nla );
1831
+ }
1832
+
1743
1833
/**
1744
1834
* nla_get_u8 - return payload of u8 attribute
1745
1835
* @nla: u8 netlink attribute
@@ -1749,6 +1839,20 @@ static inline u8 nla_get_u8(const struct nlattr *nla)
1749
1839
return * (u8 * ) nla_data (nla );
1750
1840
}
1751
1841
1842
+ /**
1843
+ * nla_get_u8_default - return payload of u8 attribute or default
1844
+ * @nla: u8 netlink attribute, may be %NULL
1845
+ * @defvalue: default value to use if @nla is %NULL
1846
+ *
1847
+ * Return: the value of the attribute, or the default value if not present
1848
+ */
1849
+ static inline u8 nla_get_u8_default (const struct nlattr * nla , u8 defvalue )
1850
+ {
1851
+ if (!nla )
1852
+ return defvalue ;
1853
+ return nla_get_u8 (nla );
1854
+ }
1855
+
1752
1856
/**
1753
1857
* nla_get_u64 - return payload of u64 attribute
1754
1858
* @nla: u64 netlink attribute
@@ -1762,6 +1866,20 @@ static inline u64 nla_get_u64(const struct nlattr *nla)
1762
1866
return tmp ;
1763
1867
}
1764
1868
1869
+ /**
1870
+ * nla_get_u64_default - return payload of u64 attribute or default
1871
+ * @nla: u64 netlink attribute, may be %NULL
1872
+ * @defvalue: default value to use if @nla is %NULL
1873
+ *
1874
+ * Return: the value of the attribute, or the default value if not present
1875
+ */
1876
+ static inline u64 nla_get_u64_default (const struct nlattr * nla , u64 defvalue )
1877
+ {
1878
+ if (!nla )
1879
+ return defvalue ;
1880
+ return nla_get_u64 (nla );
1881
+ }
1882
+
1765
1883
/**
1766
1884
* nla_get_uint - return payload of uint attribute
1767
1885
* @nla: uint netlink attribute
@@ -1773,6 +1891,20 @@ static inline u64 nla_get_uint(const struct nlattr *nla)
1773
1891
return nla_get_u64 (nla );
1774
1892
}
1775
1893
1894
+ /**
1895
+ * nla_get_uint_default - return payload of uint attribute or default
1896
+ * @nla: uint netlink attribute, may be %NULL
1897
+ * @defvalue: default value to use if @nla is %NULL
1898
+ *
1899
+ * Return: the value of the attribute, or the default value if not present
1900
+ */
1901
+ static inline u64 nla_get_uint_default (const struct nlattr * nla , u64 defvalue )
1902
+ {
1903
+ if (!nla )
1904
+ return defvalue ;
1905
+ return nla_get_uint (nla );
1906
+ }
1907
+
1776
1908
/**
1777
1909
* nla_get_be64 - return payload of __be64 attribute
1778
1910
* @nla: __be64 netlink attribute
@@ -1786,6 +1918,21 @@ static inline __be64 nla_get_be64(const struct nlattr *nla)
1786
1918
return tmp ;
1787
1919
}
1788
1920
1921
+ /**
1922
+ * nla_get_be64_default - return payload of be64 attribute or default
1923
+ * @nla: __be64 netlink attribute, may be %NULL
1924
+ * @defvalue: default value to use if @nla is %NULL
1925
+ *
1926
+ * Return: the value of the attribute, or the default value if not present
1927
+ */
1928
+ static inline __be64 nla_get_be64_default (const struct nlattr * nla ,
1929
+ __be64 defvalue )
1930
+ {
1931
+ if (!nla )
1932
+ return defvalue ;
1933
+ return nla_get_be64 (nla );
1934
+ }
1935
+
1789
1936
/**
1790
1937
* nla_get_le64 - return payload of __le64 attribute
1791
1938
* @nla: __le64 netlink attribute
@@ -1795,6 +1942,21 @@ static inline __le64 nla_get_le64(const struct nlattr *nla)
1795
1942
return * (__le64 * ) nla_data (nla );
1796
1943
}
1797
1944
1945
+ /**
1946
+ * nla_get_le64_default - return payload of le64 attribute or default
1947
+ * @nla: __le64 netlink attribute, may be %NULL
1948
+ * @defvalue: default value to use if @nla is %NULL
1949
+ *
1950
+ * Return: the value of the attribute, or the default value if not present
1951
+ */
1952
+ static inline __le64 nla_get_le64_default (const struct nlattr * nla ,
1953
+ __le64 defvalue )
1954
+ {
1955
+ if (!nla )
1956
+ return defvalue ;
1957
+ return nla_get_le64 (nla );
1958
+ }
1959
+
1798
1960
/**
1799
1961
* nla_get_s32 - return payload of s32 attribute
1800
1962
* @nla: s32 netlink attribute
@@ -1804,6 +1966,20 @@ static inline s32 nla_get_s32(const struct nlattr *nla)
1804
1966
return * (s32 * ) nla_data (nla );
1805
1967
}
1806
1968
1969
+ /**
1970
+ * nla_get_s32_default - return payload of s32 attribute or default
1971
+ * @nla: s32 netlink attribute, may be %NULL
1972
+ * @defvalue: default value to use if @nla is %NULL
1973
+ *
1974
+ * Return: the value of the attribute, or the default value if not present
1975
+ */
1976
+ static inline s32 nla_get_s32_default (const struct nlattr * nla , s32 defvalue )
1977
+ {
1978
+ if (!nla )
1979
+ return defvalue ;
1980
+ return nla_get_s32 (nla );
1981
+ }
1982
+
1807
1983
/**
1808
1984
* nla_get_s16 - return payload of s16 attribute
1809
1985
* @nla: s16 netlink attribute
@@ -1813,6 +1989,20 @@ static inline s16 nla_get_s16(const struct nlattr *nla)
1813
1989
return * (s16 * ) nla_data (nla );
1814
1990
}
1815
1991
1992
+ /**
1993
+ * nla_get_s16_default - return payload of s16 attribute or default
1994
+ * @nla: s16 netlink attribute, may be %NULL
1995
+ * @defvalue: default value to use if @nla is %NULL
1996
+ *
1997
+ * Return: the value of the attribute, or the default value if not present
1998
+ */
1999
+ static inline s16 nla_get_s16_default (const struct nlattr * nla , s16 defvalue )
2000
+ {
2001
+ if (!nla )
2002
+ return defvalue ;
2003
+ return nla_get_s16 (nla );
2004
+ }
2005
+
1816
2006
/**
1817
2007
* nla_get_s8 - return payload of s8 attribute
1818
2008
* @nla: s8 netlink attribute
@@ -1822,6 +2012,20 @@ static inline s8 nla_get_s8(const struct nlattr *nla)
1822
2012
return * (s8 * ) nla_data (nla );
1823
2013
}
1824
2014
2015
+ /**
2016
+ * nla_get_s8_default - return payload of s8 attribute or default
2017
+ * @nla: s8 netlink attribute, may be %NULL
2018
+ * @defvalue: default value to use if @nla is %NULL
2019
+ *
2020
+ * Return: the value of the attribute, or the default value if not present
2021
+ */
2022
+ static inline s8 nla_get_s8_default (const struct nlattr * nla , s8 defvalue )
2023
+ {
2024
+ if (!nla )
2025
+ return defvalue ;
2026
+ return nla_get_s8 (nla );
2027
+ }
2028
+
1825
2029
/**
1826
2030
* nla_get_s64 - return payload of s64 attribute
1827
2031
* @nla: s64 netlink attribute
@@ -1835,6 +2039,20 @@ static inline s64 nla_get_s64(const struct nlattr *nla)
1835
2039
return tmp ;
1836
2040
}
1837
2041
2042
+ /**
2043
+ * nla_get_s64_default - return payload of s64 attribute or default
2044
+ * @nla: s64 netlink attribute, may be %NULL
2045
+ * @defvalue: default value to use if @nla is %NULL
2046
+ *
2047
+ * Return: the value of the attribute, or the default value if not present
2048
+ */
2049
+ static inline s64 nla_get_s64_default (const struct nlattr * nla , s64 defvalue )
2050
+ {
2051
+ if (!nla )
2052
+ return defvalue ;
2053
+ return nla_get_s64 (nla );
2054
+ }
2055
+
1838
2056
/**
1839
2057
* nla_get_sint - return payload of uint attribute
1840
2058
* @nla: uint netlink attribute
@@ -1846,6 +2064,20 @@ static inline s64 nla_get_sint(const struct nlattr *nla)
1846
2064
return nla_get_s64 (nla );
1847
2065
}
1848
2066
2067
+ /**
2068
+ * nla_get_sint_default - return payload of sint attribute or default
2069
+ * @nla: sint netlink attribute, may be %NULL
2070
+ * @defvalue: default value to use if @nla is %NULL
2071
+ *
2072
+ * Return: the value of the attribute, or the default value if not present
2073
+ */
2074
+ static inline s64 nla_get_sint_default (const struct nlattr * nla , s64 defvalue )
2075
+ {
2076
+ if (!nla )
2077
+ return defvalue ;
2078
+ return nla_get_sint (nla );
2079
+ }
2080
+
1849
2081
/**
1850
2082
* nla_get_flag - return payload of flag attribute
1851
2083
* @nla: flag netlink attribute
@@ -1868,6 +2100,21 @@ static inline unsigned long nla_get_msecs(const struct nlattr *nla)
1868
2100
return msecs_to_jiffies ((unsigned long ) msecs );
1869
2101
}
1870
2102
2103
+ /**
2104
+ * nla_get_msecs_default - return payload of msecs attribute or default
2105
+ * @nla: msecs netlink attribute, may be %NULL
2106
+ * @defvalue: default value to use if @nla is %NULL
2107
+ *
2108
+ * Return: the value of the attribute, or the default value if not present
2109
+ */
2110
+ static inline unsigned long nla_get_msecs_default (const struct nlattr * nla ,
2111
+ unsigned long defvalue )
2112
+ {
2113
+ if (!nla )
2114
+ return defvalue ;
2115
+ return nla_get_msecs (nla );
2116
+ }
2117
+
1871
2118
/**
1872
2119
* nla_get_in_addr - return payload of IPv4 address attribute
1873
2120
* @nla: IPv4 address netlink attribute
@@ -1877,6 +2124,21 @@ static inline __be32 nla_get_in_addr(const struct nlattr *nla)
1877
2124
return * (__be32 * ) nla_data (nla );
1878
2125
}
1879
2126
2127
+ /**
2128
+ * nla_get_in_addr_default - return payload of be32 attribute or default
2129
+ * @nla: IPv4 address netlink attribute, may be %NULL
2130
+ * @defvalue: default value to use if @nla is %NULL
2131
+ *
2132
+ * Return: the value of the attribute, or the default value if not present
2133
+ */
2134
+ static inline __be32 nla_get_in_addr_default (const struct nlattr * nla ,
2135
+ __be32 defvalue )
2136
+ {
2137
+ if (!nla )
2138
+ return defvalue ;
2139
+ return nla_get_in_addr (nla );
2140
+ }
2141
+
1880
2142
/**
1881
2143
* nla_get_in6_addr - return payload of IPv6 address attribute
1882
2144
* @nla: IPv6 address netlink attribute
0 commit comments