提交 716b31ab 编写于 作者: T Thomas Graf 提交者: David S. Miller

dcbnl: Move dcb app lookup code into dcb_app_lookup()

Signed-off-by: NThomas Graf <tgraf@suug.ch>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 3d1f4869
...@@ -1716,6 +1716,22 @@ static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -1716,6 +1716,22 @@ static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
return ret; return ret;
} }
static struct dcb_app_type *dcb_app_lookup(const struct dcb_app *app,
int ifindex, int prio)
{
struct dcb_app_type *itr;
list_for_each_entry(itr, &dcb_app_list, list) {
if (itr->app.selector == app->selector &&
itr->app.protocol == app->protocol &&
itr->ifindex == ifindex &&
(!prio || itr->app.priority == prio))
return itr;
}
return NULL;
}
/** /**
* dcb_getapp - retrieve the DCBX application user priority * dcb_getapp - retrieve the DCBX application user priority
* *
...@@ -1729,14 +1745,8 @@ u8 dcb_getapp(struct net_device *dev, struct dcb_app *app) ...@@ -1729,14 +1745,8 @@ u8 dcb_getapp(struct net_device *dev, struct dcb_app *app)
u8 prio = 0; u8 prio = 0;
spin_lock(&dcb_lock); spin_lock(&dcb_lock);
list_for_each_entry(itr, &dcb_app_list, list) { if ((itr = dcb_app_lookup(app, dev->ifindex, 0)))
if (itr->app.selector == app->selector &&
itr->app.protocol == app->protocol &&
itr->ifindex == dev->ifindex) {
prio = itr->app.priority; prio = itr->app.priority;
break;
}
}
spin_unlock(&dcb_lock); spin_unlock(&dcb_lock);
return prio; return prio;
...@@ -1762,10 +1772,7 @@ int dcb_setapp(struct net_device *dev, struct dcb_app *new) ...@@ -1762,10 +1772,7 @@ int dcb_setapp(struct net_device *dev, struct dcb_app *new)
spin_lock(&dcb_lock); spin_lock(&dcb_lock);
/* Search for existing match and replace */ /* Search for existing match and replace */
list_for_each_entry(itr, &dcb_app_list, list) { if ((itr = dcb_app_lookup(new, dev->ifindex, 0))) {
if (itr->app.selector == new->selector &&
itr->app.protocol == new->protocol &&
itr->ifindex == dev->ifindex) {
if (new->priority) if (new->priority)
itr->app.priority = new->priority; itr->app.priority = new->priority;
else { else {
...@@ -1774,7 +1781,6 @@ int dcb_setapp(struct net_device *dev, struct dcb_app *new) ...@@ -1774,7 +1781,6 @@ int dcb_setapp(struct net_device *dev, struct dcb_app *new)
} }
goto out; goto out;
} }
}
/* App type does not exist add new application type */ /* App type does not exist add new application type */
if (new->priority) { if (new->priority) {
struct dcb_app_type *entry; struct dcb_app_type *entry;
...@@ -1808,13 +1814,8 @@ u8 dcb_ieee_getapp_mask(struct net_device *dev, struct dcb_app *app) ...@@ -1808,13 +1814,8 @@ u8 dcb_ieee_getapp_mask(struct net_device *dev, struct dcb_app *app)
u8 prio = 0; u8 prio = 0;
spin_lock(&dcb_lock); spin_lock(&dcb_lock);
list_for_each_entry(itr, &dcb_app_list, list) { if ((itr = dcb_app_lookup(app, dev->ifindex, 0)))
if (itr->app.selector == app->selector &&
itr->app.protocol == app->protocol &&
itr->ifindex == dev->ifindex) {
prio |= 1 << itr->app.priority; prio |= 1 << itr->app.priority;
}
}
spin_unlock(&dcb_lock); spin_unlock(&dcb_lock);
return prio; return prio;
...@@ -1830,7 +1831,7 @@ EXPORT_SYMBOL(dcb_ieee_getapp_mask); ...@@ -1830,7 +1831,7 @@ EXPORT_SYMBOL(dcb_ieee_getapp_mask);
*/ */
int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new) int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new)
{ {
struct dcb_app_type *itr, *entry; struct dcb_app_type *entry;
struct dcb_app_type event; struct dcb_app_type event;
int err = 0; int err = 0;
...@@ -1841,15 +1842,10 @@ int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new) ...@@ -1841,15 +1842,10 @@ int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new)
spin_lock(&dcb_lock); spin_lock(&dcb_lock);
/* Search for existing match and abort if found */ /* Search for existing match and abort if found */
list_for_each_entry(itr, &dcb_app_list, list) { if (dcb_app_lookup(new, dev->ifindex, new->priority)) {
if (itr->app.selector == new->selector &&
itr->app.protocol == new->protocol &&
itr->app.priority == new->priority &&
itr->ifindex == dev->ifindex) {
err = -EEXIST; err = -EEXIST;
goto out; goto out;
} }
}
/* App entry does not exist add new entry */ /* App entry does not exist add new entry */
entry = kmalloc(sizeof(struct dcb_app_type), GFP_ATOMIC); entry = kmalloc(sizeof(struct dcb_app_type), GFP_ATOMIC);
...@@ -1887,19 +1883,12 @@ int dcb_ieee_delapp(struct net_device *dev, struct dcb_app *del) ...@@ -1887,19 +1883,12 @@ int dcb_ieee_delapp(struct net_device *dev, struct dcb_app *del)
spin_lock(&dcb_lock); spin_lock(&dcb_lock);
/* Search for existing match and remove it. */ /* Search for existing match and remove it. */
list_for_each_entry(itr, &dcb_app_list, list) { if ((itr = dcb_app_lookup(del, dev->ifindex, del->priority))) {
if (itr->app.selector == del->selector &&
itr->app.protocol == del->protocol &&
itr->app.priority == del->priority &&
itr->ifindex == dev->ifindex) {
list_del(&itr->list); list_del(&itr->list);
kfree(itr); kfree(itr);
err = 0; err = 0;
goto out;
}
} }
out:
spin_unlock(&dcb_lock); spin_unlock(&dcb_lock);
if (!err) if (!err)
call_dcbevent_notifiers(DCB_APP_EVENT, &event); call_dcbevent_notifiers(DCB_APP_EVENT, &event);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册