diff options
author | Thomas Graf <tgraf@suug.ch> | 2012-06-12 22:54:59 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-06-13 18:46:35 -0400 |
commit | 716b31abbd39baab307c0a7b38dce9a20c16c62d (patch) | |
tree | 9aaf6a4724aeb44f5040c187025afb1a1f834a3d /net/dcb | |
parent | 3d1f486952b750f1cca53cf22d4f769db5aba4f0 (diff) |
dcbnl: Move dcb app lookup code into dcb_app_lookup()
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dcb')
-rw-r--r-- | net/dcb/dcbnl.c | 81 |
1 files changed, 35 insertions, 46 deletions
diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c index 5a5bc25b70d3..6817f1439951 100644 --- a/net/dcb/dcbnl.c +++ b/net/dcb/dcbnl.c | |||
@@ -1716,6 +1716,22 @@ out: | |||
1716 | return ret; | 1716 | return ret; |
1717 | } | 1717 | } |
1718 | 1718 | ||
1719 | static struct dcb_app_type *dcb_app_lookup(const struct dcb_app *app, | ||
1720 | int ifindex, int prio) | ||
1721 | { | ||
1722 | struct dcb_app_type *itr; | ||
1723 | |||
1724 | list_for_each_entry(itr, &dcb_app_list, list) { | ||
1725 | if (itr->app.selector == app->selector && | ||
1726 | itr->app.protocol == app->protocol && | ||
1727 | itr->ifindex == ifindex && | ||
1728 | (!prio || itr->app.priority == prio)) | ||
1729 | return itr; | ||
1730 | } | ||
1731 | |||
1732 | return NULL; | ||
1733 | } | ||
1734 | |||
1719 | /** | 1735 | /** |
1720 | * dcb_getapp - retrieve the DCBX application user priority | 1736 | * dcb_getapp - retrieve the DCBX application user priority |
1721 | * | 1737 | * |
@@ -1729,14 +1745,8 @@ u8 dcb_getapp(struct net_device *dev, struct dcb_app *app) | |||
1729 | u8 prio = 0; | 1745 | u8 prio = 0; |
1730 | 1746 | ||
1731 | spin_lock(&dcb_lock); | 1747 | spin_lock(&dcb_lock); |
1732 | list_for_each_entry(itr, &dcb_app_list, list) { | 1748 | if ((itr = dcb_app_lookup(app, dev->ifindex, 0))) |
1733 | if (itr->app.selector == app->selector && | 1749 | prio = itr->app.priority; |
1734 | itr->app.protocol == app->protocol && | ||
1735 | itr->ifindex == dev->ifindex) { | ||
1736 | prio = itr->app.priority; | ||
1737 | break; | ||
1738 | } | ||
1739 | } | ||
1740 | spin_unlock(&dcb_lock); | 1750 | spin_unlock(&dcb_lock); |
1741 | 1751 | ||
1742 | return prio; | 1752 | return prio; |
@@ -1762,18 +1772,14 @@ int dcb_setapp(struct net_device *dev, struct dcb_app *new) | |||
1762 | 1772 | ||
1763 | spin_lock(&dcb_lock); | 1773 | spin_lock(&dcb_lock); |
1764 | /* Search for existing match and replace */ | 1774 | /* Search for existing match and replace */ |
1765 | list_for_each_entry(itr, &dcb_app_list, list) { | 1775 | if ((itr = dcb_app_lookup(new, dev->ifindex, 0))) { |
1766 | if (itr->app.selector == new->selector && | 1776 | if (new->priority) |
1767 | itr->app.protocol == new->protocol && | 1777 | itr->app.priority = new->priority; |
1768 | itr->ifindex == dev->ifindex) { | 1778 | else { |
1769 | if (new->priority) | 1779 | list_del(&itr->list); |
1770 | itr->app.priority = new->priority; | 1780 | kfree(itr); |
1771 | else { | ||
1772 | list_del(&itr->list); | ||
1773 | kfree(itr); | ||
1774 | } | ||
1775 | goto out; | ||
1776 | } | 1781 | } |
1782 | goto out; | ||
1777 | } | 1783 | } |
1778 | /* App type does not exist add new application type */ | 1784 | /* App type does not exist add new application type */ |
1779 | if (new->priority) { | 1785 | if (new->priority) { |
@@ -1808,13 +1814,8 @@ u8 dcb_ieee_getapp_mask(struct net_device *dev, struct dcb_app *app) | |||
1808 | u8 prio = 0; | 1814 | u8 prio = 0; |
1809 | 1815 | ||
1810 | spin_lock(&dcb_lock); | 1816 | spin_lock(&dcb_lock); |
1811 | list_for_each_entry(itr, &dcb_app_list, list) { | 1817 | if ((itr = dcb_app_lookup(app, dev->ifindex, 0))) |
1812 | if (itr->app.selector == app->selector && | 1818 | prio |= 1 << itr->app.priority; |
1813 | itr->app.protocol == app->protocol && | ||
1814 | itr->ifindex == dev->ifindex) { | ||
1815 | prio |= 1 << itr->app.priority; | ||
1816 | } | ||
1817 | } | ||
1818 | spin_unlock(&dcb_lock); | 1819 | spin_unlock(&dcb_lock); |
1819 | 1820 | ||
1820 | return prio; | 1821 | return prio; |
@@ -1830,7 +1831,7 @@ EXPORT_SYMBOL(dcb_ieee_getapp_mask); | |||
1830 | */ | 1831 | */ |
1831 | int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new) | 1832 | int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new) |
1832 | { | 1833 | { |
1833 | struct dcb_app_type *itr, *entry; | 1834 | struct dcb_app_type *entry; |
1834 | struct dcb_app_type event; | 1835 | struct dcb_app_type event; |
1835 | int err = 0; | 1836 | int err = 0; |
1836 | 1837 | ||
@@ -1841,14 +1842,9 @@ int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new) | |||
1841 | 1842 | ||
1842 | spin_lock(&dcb_lock); | 1843 | spin_lock(&dcb_lock); |
1843 | /* Search for existing match and abort if found */ | 1844 | /* Search for existing match and abort if found */ |
1844 | list_for_each_entry(itr, &dcb_app_list, list) { | 1845 | if (dcb_app_lookup(new, dev->ifindex, new->priority)) { |
1845 | if (itr->app.selector == new->selector && | 1846 | err = -EEXIST; |
1846 | itr->app.protocol == new->protocol && | 1847 | goto out; |
1847 | itr->app.priority == new->priority && | ||
1848 | itr->ifindex == dev->ifindex) { | ||
1849 | err = -EEXIST; | ||
1850 | goto out; | ||
1851 | } | ||
1852 | } | 1848 | } |
1853 | 1849 | ||
1854 | /* App entry does not exist add new entry */ | 1850 | /* App entry does not exist add new entry */ |
@@ -1887,19 +1883,12 @@ int dcb_ieee_delapp(struct net_device *dev, struct dcb_app *del) | |||
1887 | 1883 | ||
1888 | spin_lock(&dcb_lock); | 1884 | spin_lock(&dcb_lock); |
1889 | /* Search for existing match and remove it. */ | 1885 | /* Search for existing match and remove it. */ |
1890 | list_for_each_entry(itr, &dcb_app_list, list) { | 1886 | if ((itr = dcb_app_lookup(del, dev->ifindex, del->priority))) { |
1891 | if (itr->app.selector == del->selector && | 1887 | list_del(&itr->list); |
1892 | itr->app.protocol == del->protocol && | 1888 | kfree(itr); |
1893 | itr->app.priority == del->priority && | 1889 | err = 0; |
1894 | itr->ifindex == dev->ifindex) { | ||
1895 | list_del(&itr->list); | ||
1896 | kfree(itr); | ||
1897 | err = 0; | ||
1898 | goto out; | ||
1899 | } | ||
1900 | } | 1890 | } |
1901 | 1891 | ||
1902 | out: | ||
1903 | spin_unlock(&dcb_lock); | 1892 | spin_unlock(&dcb_lock); |
1904 | if (!err) | 1893 | if (!err) |
1905 | call_dcbevent_notifiers(DCB_APP_EVENT, &event); | 1894 | call_dcbevent_notifiers(DCB_APP_EVENT, &event); |