aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2006-08-07 20:58:53 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2006-09-22 17:54:02 -0400
commit6b3f8674bccbb2e784d01e44373fb730af6cb149 (patch)
treef6632cf6c5a06d79e3023aa5828600d64d348907
parent9067c722cf6930adf1df2d169de9094dd90b0c33 (diff)
[NEIGH]: Convert neighbour table modification to new netlink api
Signed-off-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/core/neighbour.c172
1 files changed, 104 insertions, 68 deletions
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 5490afd23b82..5a0b8f48a099 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1754,28 +1754,61 @@ static inline struct neigh_parms *lookup_neigh_params(struct neigh_table *tbl,
1754 return NULL; 1754 return NULL;
1755} 1755}
1756 1756
1757static struct nla_policy nl_neightbl_policy[NDTA_MAX+1] __read_mostly = {
1758 [NDTA_NAME] = { .type = NLA_STRING },
1759 [NDTA_THRESH1] = { .type = NLA_U32 },
1760 [NDTA_THRESH2] = { .type = NLA_U32 },
1761 [NDTA_THRESH3] = { .type = NLA_U32 },
1762 [NDTA_GC_INTERVAL] = { .type = NLA_U64 },
1763 [NDTA_PARMS] = { .type = NLA_NESTED },
1764};
1765
1766static struct nla_policy nl_ntbl_parm_policy[NDTPA_MAX+1] __read_mostly = {
1767 [NDTPA_IFINDEX] = { .type = NLA_U32 },
1768 [NDTPA_QUEUE_LEN] = { .type = NLA_U32 },
1769 [NDTPA_PROXY_QLEN] = { .type = NLA_U32 },
1770 [NDTPA_APP_PROBES] = { .type = NLA_U32 },
1771 [NDTPA_UCAST_PROBES] = { .type = NLA_U32 },
1772 [NDTPA_MCAST_PROBES] = { .type = NLA_U32 },
1773 [NDTPA_BASE_REACHABLE_TIME] = { .type = NLA_U64 },
1774 [NDTPA_GC_STALETIME] = { .type = NLA_U64 },
1775 [NDTPA_DELAY_PROBE_TIME] = { .type = NLA_U64 },
1776 [NDTPA_RETRANS_TIME] = { .type = NLA_U64 },
1777 [NDTPA_ANYCAST_DELAY] = { .type = NLA_U64 },
1778 [NDTPA_PROXY_DELAY] = { .type = NLA_U64 },
1779 [NDTPA_LOCKTIME] = { .type = NLA_U64 },
1780};
1781
1757int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 1782int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1758{ 1783{
1759 struct neigh_table *tbl; 1784 struct neigh_table *tbl;
1760 struct ndtmsg *ndtmsg = NLMSG_DATA(nlh); 1785 struct ndtmsg *ndtmsg;
1761 struct rtattr **tb = arg; 1786 struct nlattr *tb[NDTA_MAX+1];
1762 int err = -EINVAL; 1787 int err;
1763 1788
1764 if (!tb[NDTA_NAME - 1] || !RTA_PAYLOAD(tb[NDTA_NAME - 1])) 1789 err = nlmsg_parse(nlh, sizeof(*ndtmsg), tb, NDTA_MAX,
1765 return -EINVAL; 1790 nl_neightbl_policy);
1791 if (err < 0)
1792 goto errout;
1793
1794 if (tb[NDTA_NAME] == NULL) {
1795 err = -EINVAL;
1796 goto errout;
1797 }
1766 1798
1799 ndtmsg = nlmsg_data(nlh);
1767 read_lock(&neigh_tbl_lock); 1800 read_lock(&neigh_tbl_lock);
1768 for (tbl = neigh_tables; tbl; tbl = tbl->next) { 1801 for (tbl = neigh_tables; tbl; tbl = tbl->next) {
1769 if (ndtmsg->ndtm_family && tbl->family != ndtmsg->ndtm_family) 1802 if (ndtmsg->ndtm_family && tbl->family != ndtmsg->ndtm_family)
1770 continue; 1803 continue;
1771 1804
1772 if (!rtattr_strcmp(tb[NDTA_NAME - 1], tbl->id)) 1805 if (nla_strcmp(tb[NDTA_NAME], tbl->id) == 0)
1773 break; 1806 break;
1774 } 1807 }
1775 1808
1776 if (tbl == NULL) { 1809 if (tbl == NULL) {
1777 err = -ENOENT; 1810 err = -ENOENT;
1778 goto errout; 1811 goto errout_locked;
1779 } 1812 }
1780 1813
1781 /* 1814 /*
@@ -1784,86 +1817,89 @@ int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1784 */ 1817 */
1785 write_lock_bh(&tbl->lock); 1818 write_lock_bh(&tbl->lock);
1786 1819
1787 if (tb[NDTA_THRESH1 - 1]) 1820 if (tb[NDTA_PARMS]) {
1788 tbl->gc_thresh1 = RTA_GET_U32(tb[NDTA_THRESH1 - 1]); 1821 struct nlattr *tbp[NDTPA_MAX+1];
1789
1790 if (tb[NDTA_THRESH2 - 1])
1791 tbl->gc_thresh2 = RTA_GET_U32(tb[NDTA_THRESH2 - 1]);
1792
1793 if (tb[NDTA_THRESH3 - 1])
1794 tbl->gc_thresh3 = RTA_GET_U32(tb[NDTA_THRESH3 - 1]);
1795
1796 if (tb[NDTA_GC_INTERVAL - 1])
1797 tbl->gc_interval = RTA_GET_MSECS(tb[NDTA_GC_INTERVAL - 1]);
1798
1799 if (tb[NDTA_PARMS - 1]) {
1800 struct rtattr *tbp[NDTPA_MAX];
1801 struct neigh_parms *p; 1822 struct neigh_parms *p;
1802 u32 ifindex = 0; 1823 int i, ifindex = 0;
1803 1824
1804 if (rtattr_parse_nested(tbp, NDTPA_MAX, tb[NDTA_PARMS - 1]) < 0) 1825 err = nla_parse_nested(tbp, NDTPA_MAX, tb[NDTA_PARMS],
1805 goto rtattr_failure; 1826 nl_ntbl_parm_policy);
1827 if (err < 0)
1828 goto errout_tbl_lock;
1806 1829
1807 if (tbp[NDTPA_IFINDEX - 1]) 1830 if (tbp[NDTPA_IFINDEX])
1808 ifindex = RTA_GET_U32(tbp[NDTPA_IFINDEX - 1]); 1831 ifindex = nla_get_u32(tbp[NDTPA_IFINDEX]);
1809 1832
1810 p = lookup_neigh_params(tbl, ifindex); 1833 p = lookup_neigh_params(tbl, ifindex);
1811 if (p == NULL) { 1834 if (p == NULL) {
1812 err = -ENOENT; 1835 err = -ENOENT;
1813 goto rtattr_failure; 1836 goto errout_tbl_lock;
1814 } 1837 }
1815
1816 if (tbp[NDTPA_QUEUE_LEN - 1])
1817 p->queue_len = RTA_GET_U32(tbp[NDTPA_QUEUE_LEN - 1]);
1818
1819 if (tbp[NDTPA_PROXY_QLEN - 1])
1820 p->proxy_qlen = RTA_GET_U32(tbp[NDTPA_PROXY_QLEN - 1]);
1821
1822 if (tbp[NDTPA_APP_PROBES - 1])
1823 p->app_probes = RTA_GET_U32(tbp[NDTPA_APP_PROBES - 1]);
1824
1825 if (tbp[NDTPA_UCAST_PROBES - 1])
1826 p->ucast_probes =
1827 RTA_GET_U32(tbp[NDTPA_UCAST_PROBES - 1]);
1828 1838
1829 if (tbp[NDTPA_MCAST_PROBES - 1]) 1839 for (i = 1; i <= NDTPA_MAX; i++) {
1830 p->mcast_probes = 1840 if (tbp[i] == NULL)
1831 RTA_GET_U32(tbp[NDTPA_MCAST_PROBES - 1]); 1841 continue;
1832
1833 if (tbp[NDTPA_BASE_REACHABLE_TIME - 1])
1834 p->base_reachable_time =
1835 RTA_GET_MSECS(tbp[NDTPA_BASE_REACHABLE_TIME - 1]);
1836
1837 if (tbp[NDTPA_GC_STALETIME - 1])
1838 p->gc_staletime =
1839 RTA_GET_MSECS(tbp[NDTPA_GC_STALETIME - 1]);
1840 1842
1841 if (tbp[NDTPA_DELAY_PROBE_TIME - 1]) 1843 switch (i) {
1842 p->delay_probe_time = 1844 case NDTPA_QUEUE_LEN:
1843 RTA_GET_MSECS(tbp[NDTPA_DELAY_PROBE_TIME - 1]); 1845 p->queue_len = nla_get_u32(tbp[i]);
1846 break;
1847 case NDTPA_PROXY_QLEN:
1848 p->proxy_qlen = nla_get_u32(tbp[i]);
1849 break;
1850 case NDTPA_APP_PROBES:
1851 p->app_probes = nla_get_u32(tbp[i]);
1852 break;
1853 case NDTPA_UCAST_PROBES:
1854 p->ucast_probes = nla_get_u32(tbp[i]);
1855 break;
1856 case NDTPA_MCAST_PROBES:
1857 p->mcast_probes = nla_get_u32(tbp[i]);
1858 break;
1859 case NDTPA_BASE_REACHABLE_TIME:
1860 p->base_reachable_time = nla_get_msecs(tbp[i]);
1861 break;
1862 case NDTPA_GC_STALETIME:
1863 p->gc_staletime = nla_get_msecs(tbp[i]);
1864 break;
1865 case NDTPA_DELAY_PROBE_TIME:
1866 p->delay_probe_time = nla_get_msecs(tbp[i]);
1867 break;
1868 case NDTPA_RETRANS_TIME:
1869 p->retrans_time = nla_get_msecs(tbp[i]);
1870 break;
1871 case NDTPA_ANYCAST_DELAY:
1872 p->anycast_delay = nla_get_msecs(tbp[i]);
1873 break;
1874 case NDTPA_PROXY_DELAY:
1875 p->proxy_delay = nla_get_msecs(tbp[i]);
1876 break;
1877 case NDTPA_LOCKTIME:
1878 p->locktime = nla_get_msecs(tbp[i]);
1879 break;
1880 }
1881 }
1882 }
1844 1883
1845 if (tbp[NDTPA_RETRANS_TIME - 1]) 1884 if (tb[NDTA_THRESH1])
1846 p->retrans_time = 1885 tbl->gc_thresh1 = nla_get_u32(tb[NDTA_THRESH1]);
1847 RTA_GET_MSECS(tbp[NDTPA_RETRANS_TIME - 1]);
1848 1886
1849 if (tbp[NDTPA_ANYCAST_DELAY - 1]) 1887 if (tb[NDTA_THRESH2])
1850 p->anycast_delay = 1888 tbl->gc_thresh2 = nla_get_u32(tb[NDTA_THRESH2]);
1851 RTA_GET_MSECS(tbp[NDTPA_ANYCAST_DELAY - 1]);
1852 1889
1853 if (tbp[NDTPA_PROXY_DELAY - 1]) 1890 if (tb[NDTA_THRESH3])
1854 p->proxy_delay = 1891 tbl->gc_thresh3 = nla_get_u32(tb[NDTA_THRESH3]);
1855 RTA_GET_MSECS(tbp[NDTPA_PROXY_DELAY - 1]);
1856 1892
1857 if (tbp[NDTPA_LOCKTIME - 1]) 1893 if (tb[NDTA_GC_INTERVAL])
1858 p->locktime = RTA_GET_MSECS(tbp[NDTPA_LOCKTIME - 1]); 1894 tbl->gc_interval = nla_get_msecs(tb[NDTA_GC_INTERVAL]);
1859 }
1860 1895
1861 err = 0; 1896 err = 0;
1862 1897
1863rtattr_failure: 1898errout_tbl_lock:
1864 write_unlock_bh(&tbl->lock); 1899 write_unlock_bh(&tbl->lock);
1865errout: 1900errout_locked:
1866 read_unlock(&neigh_tbl_lock); 1901 read_unlock(&neigh_tbl_lock);
1902errout:
1867 return err; 1903 return err;
1868} 1904}
1869 1905