mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2025-02-21 03:23:04 -05:00
VLAN: Avoid use of libnl cache
Using rtnl_link_alloc_cache() is expensive as it fills in all configured links. Using rtnl_link_get_kernel() is much more lightweight. Signed-off-by: Michael Braun <michael-dev@fami-braun.de>
This commit is contained in:
parent
732b1d20ec
commit
5aef495fda
@ -33,7 +33,6 @@ int vlan_add(const char *if_name, int vid, const char *vlan_if_name)
|
|||||||
{
|
{
|
||||||
int err, ret = -1;
|
int err, ret = -1;
|
||||||
struct nl_sock *handle = NULL;
|
struct nl_sock *handle = NULL;
|
||||||
struct nl_cache *cache = NULL;
|
|
||||||
struct rtnl_link *rlink = NULL;
|
struct rtnl_link *rlink = NULL;
|
||||||
int if_idx = 0;
|
int if_idx = 0;
|
||||||
|
|
||||||
@ -65,22 +64,19 @@ int vlan_add(const char *if_name, int vid, const char *vlan_if_name)
|
|||||||
goto vlan_add_error;
|
goto vlan_add_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = rtnl_link_alloc_cache(handle, AF_UNSPEC, &cache);
|
err = rtnl_link_get_kernel(handle, 0, if_name, &rlink);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
cache = NULL;
|
|
||||||
wpa_printf(MSG_ERROR, "VLAN: failed to alloc cache: %s",
|
|
||||||
nl_geterror(err));
|
|
||||||
goto vlan_add_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(if_idx = rtnl_link_name2i(cache, if_name))) {
|
|
||||||
/* link does not exist */
|
/* link does not exist */
|
||||||
wpa_printf(MSG_ERROR, "VLAN: interface %s does not exist",
|
wpa_printf(MSG_ERROR, "VLAN: interface %s does not exist",
|
||||||
if_name);
|
if_name);
|
||||||
goto vlan_add_error;
|
goto vlan_add_error;
|
||||||
}
|
}
|
||||||
|
if_idx = rtnl_link_get_ifindex(rlink);
|
||||||
|
rtnl_link_put(rlink);
|
||||||
|
rlink = NULL;
|
||||||
|
|
||||||
if ((rlink = rtnl_link_get_by_name(cache, vlan_if_name))) {
|
err = rtnl_link_get_kernel(handle, 0, vlan_if_name, &rlink);
|
||||||
|
if (err >= 0) {
|
||||||
/* link does exist */
|
/* link does exist */
|
||||||
rtnl_link_put(rlink);
|
rtnl_link_put(rlink);
|
||||||
rlink = NULL;
|
rlink = NULL;
|
||||||
@ -127,8 +123,6 @@ int vlan_add(const char *if_name, int vid, const char *vlan_if_name)
|
|||||||
vlan_add_error:
|
vlan_add_error:
|
||||||
if (rlink)
|
if (rlink)
|
||||||
rtnl_link_put(rlink);
|
rtnl_link_put(rlink);
|
||||||
if (cache)
|
|
||||||
nl_cache_free(cache);
|
|
||||||
if (handle)
|
if (handle)
|
||||||
nl_socket_free(handle);
|
nl_socket_free(handle);
|
||||||
return ret;
|
return ret;
|
||||||
@ -139,7 +133,6 @@ int vlan_rem(const char *if_name)
|
|||||||
{
|
{
|
||||||
int err, ret = -1;
|
int err, ret = -1;
|
||||||
struct nl_sock *handle = NULL;
|
struct nl_sock *handle = NULL;
|
||||||
struct nl_cache *cache = NULL;
|
|
||||||
struct rtnl_link *rlink = NULL;
|
struct rtnl_link *rlink = NULL;
|
||||||
|
|
||||||
wpa_printf(MSG_DEBUG, "VLAN: vlan_rem(if_name=%s)", if_name);
|
wpa_printf(MSG_DEBUG, "VLAN: vlan_rem(if_name=%s)", if_name);
|
||||||
@ -157,15 +150,8 @@ int vlan_rem(const char *if_name)
|
|||||||
goto vlan_rem_error;
|
goto vlan_rem_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = rtnl_link_alloc_cache(handle, AF_UNSPEC, &cache);
|
err = rtnl_link_get_kernel(handle, 0, if_name, &rlink);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
cache = NULL;
|
|
||||||
wpa_printf(MSG_ERROR, "VLAN: failed to alloc cache: %s",
|
|
||||||
nl_geterror(err));
|
|
||||||
goto vlan_rem_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(rlink = rtnl_link_get_by_name(cache, if_name))) {
|
|
||||||
/* link does not exist */
|
/* link does not exist */
|
||||||
wpa_printf(MSG_ERROR, "VLAN: interface %s does not exists",
|
wpa_printf(MSG_ERROR, "VLAN: interface %s does not exists",
|
||||||
if_name);
|
if_name);
|
||||||
@ -184,8 +170,6 @@ int vlan_rem(const char *if_name)
|
|||||||
vlan_rem_error:
|
vlan_rem_error:
|
||||||
if (rlink)
|
if (rlink)
|
||||||
rtnl_link_put(rlink);
|
rtnl_link_put(rlink);
|
||||||
if (cache)
|
|
||||||
nl_cache_free(cache);
|
|
||||||
if (handle)
|
if (handle)
|
||||||
nl_socket_free(handle);
|
nl_socket_free(handle);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user