Commit f6c53334 authored by Junwei Zhang's avatar Junwei Zhang Committed by David S. Miller

net: only check perm protocol when register proto

The permanent protocol nodes are at the head of the list,
So only need check all these nodes.

No matter the new node is permanent or not,
insert the new node after the last permanent protocol node,

If the new node conflicts with existing permanent node,
return error.
Signed-off-by: default avatarMartin Zhang <martinbj2008@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4b1b865e
...@@ -1043,23 +1043,17 @@ void inet_register_protosw(struct inet_protosw *p) ...@@ -1043,23 +1043,17 @@ void inet_register_protosw(struct inet_protosw *p)
goto out_illegal; goto out_illegal;
/* If we are trying to override a permanent protocol, bail. */ /* If we are trying to override a permanent protocol, bail. */
answer = NULL;
last_perm = &inetsw[p->type]; last_perm = &inetsw[p->type];
list_for_each(lh, &inetsw[p->type]) { list_for_each(lh, &inetsw[p->type]) {
answer = list_entry(lh, struct inet_protosw, list); answer = list_entry(lh, struct inet_protosw, list);
/* Check only the non-wild match. */ /* Check only the non-wild match. */
if (INET_PROTOSW_PERMANENT & answer->flags) { if ((INET_PROTOSW_PERMANENT & answer->flags) == 0)
if (protocol == answer->protocol)
break; break;
if (protocol == answer->protocol)
goto out_permanent;
last_perm = lh; last_perm = lh;
} }
answer = NULL;
}
if (answer)
goto out_permanent;
/* Add the new entry after the last permanent entry if any, so that /* Add the new entry after the last permanent entry if any, so that
* the new entry does not override a permanent entry when matched with * the new entry does not override a permanent entry when matched with
* a wild-card protocol. But it is allowed to override any existing * a wild-card protocol. But it is allowed to override any existing
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment