Skip to content

Commit

Permalink
fix(rtnl): Add Linux kernel version check for IFA_RT_PRIORITY
Browse files Browse the repository at this point in the history
This commit adds a version check for the IFA_RT_PRIORITY constant,
which was introduced in Linux kernel 4.18. The constant is now only
defined if the kernel version is greater than 4.17.0.

Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
zhaojh329 committed Aug 1, 2024
1 parent bdca677 commit 52c2832
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,14 @@ local function do_address(action, dev, addr)
msg:put_attr_str(rtnl.IFA_LABEL, addr.label)
end

if addr.metric then
msg:put_attr_u32(rtnl.IFA_RT_PRIORITY, addr.metric)
end
if rtnl.IFA_RT_PRIORITY then
if addr.metric then
msg:put_attr_u32(rtnl.IFA_RT_PRIORITY, addr.metric)
end

if addr.priority then
msg:put_attr_u32(rtnl.IFA_RT_PRIORITY, addr.priority)
if addr.priority then
msg:put_attr_u32(rtnl.IFA_RT_PRIORITY, addr.priority)
end
end

return rtnl_send(msg)
Expand Down
4 changes: 4 additions & 0 deletions rtnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Author: Jianhui Zhao <[email protected]>
*/

#include <linux/version.h>
#include <linux/rtnetlink.h>
#include <linux/if.h>

Expand Down Expand Up @@ -289,7 +290,10 @@ int luaopen_eco_rtnl(lua_State *L)
lua_add_constant(L, "IFA_CACHEINFO", IFA_CACHEINFO);
lua_add_constant(L, "IFA_MULTICAST", IFA_MULTICAST);
lua_add_constant(L, "IFA_FLAGS", IFA_FLAGS);

#if LINUX_VERSION_CODE > KERNEL_VERSION(4,17,0)
lua_add_constant(L, "IFA_RT_PRIORITY", IFA_RT_PRIORITY);
#endif

lua_add_constant(L, "RTNLGRP_LINK", RTNLGRP_LINK);
lua_add_constant(L, "RTNLGRP_NOTIFY", RTNLGRP_NOTIFY);
Expand Down

0 comments on commit 52c2832

Please sign in to comment.