Skip to content

Commit b24be6e

Browse files
committed
luaskb: add priority getter and setter
Signed-off-by: Ashwani Kumar Kamal <ashwanikamal.im421@gmail.com>
1 parent 3ca03e1 commit b24be6e

3 files changed

Lines changed: 68 additions & 9 deletions

File tree

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ scripts_install:
8080
${MKDIR} ${SCRIPTS_INSTALL_PATH}
8181
${MKDIR} ${SCRIPTS_INSTALL_PATH}/lunatik
8282
${MKDIR} ${SCRIPTS_INSTALL_PATH}/socket
83+
${MKDIR} ${SCRIPTS_INSTALL_PATH}/skb
8384
${MKDIR} ${SCRIPTS_INSTALL_PATH}/syscall
8485
${MKDIR} ${SCRIPTS_INSTALL_PATH}/crypto
8586
${MKDIR} ${SCRIPTS_INSTALL_PATH}/linux
@@ -91,6 +92,7 @@ scripts_install:
9192
${INSTALL} -m 0644 lib/lighten.lua ${SCRIPTS_INSTALL_PATH}/
9293
${INSTALL} -m 0644 lib/lunatik/*.lua ${SCRIPTS_INSTALL_PATH}/lunatik
9394
${INSTALL} -m 0644 lib/socket/*.lua ${SCRIPTS_INSTALL_PATH}/socket
95+
${INSTALL} -m 0644 lib/skb/*.lua ${SCRIPTS_INSTALL_PATH}/skb
9496
${INSTALL} -m 0644 lib/syscall/*.lua ${SCRIPTS_INSTALL_PATH}/syscall
9597
${INSTALL} -m 0644 lib/crypto/*.lua ${SCRIPTS_INSTALL_PATH}/crypto
9698
# NOTE: `lib/linux/` exists only as LDoc stubs (see doc-stubs); never install it.

config.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ file = {
3838
'./lib/net.lua',
3939
'./lib/luanetfilter.c',
4040
'./lib/luaskb.c',
41+
'./lib/skb/attr.lua',
4142
'./lib/luanotifier.c',
4243
'./lib/luaprobe.c',
4344
'./lib/luarcu.c',

lib/luaskb.c

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,55 @@ static int luaskb_forward(lua_State *L)
195195
return 0;
196196
}
197197

198+
static int luaskb_getmark(lua_State *L)
199+
{
200+
luaskb_t *lskb = luaskb_check(L, 1);
201+
lua_pushinteger(L, lskb->skb->mark);
202+
return 1;
203+
}
204+
205+
static int luaskb_setmark(lua_State *L)
206+
{
207+
luaskb_t *lskb = luaskb_check(L, 1);
208+
lskb->skb->mark = (u32)luaL_checkinteger(L, 2);
209+
return 0;
210+
}
211+
212+
static int luaskb_getpriority(lua_State *L)
213+
{
214+
luaskb_t *lskb = luaskb_check(L, 1);
215+
lua_pushinteger(L, lskb->skb->priority);
216+
return 1;
217+
}
218+
219+
static int luaskb_setpriority(lua_State *L)
220+
{
221+
luaskb_t *lskb = luaskb_check(L, 1);
222+
lskb->skb->priority = (u32)luaL_checkinteger(L, 2);
223+
return 0;
224+
}
225+
226+
static int luaskb_protocol(lua_State *L)
227+
{
228+
luaskb_t *lskb = luaskb_check(L, 1);
229+
lua_pushinteger(L, ntohs(lskb->skb->protocol));
230+
return 1;
231+
}
232+
233+
static int luaskb_proto(lua_State *L)
234+
{
235+
luaskb_t *lskb = luaskb_check(L, 1);
236+
struct sk_buff *skb = lskb->skb;
237+
238+
if (skb->protocol == htons(ETH_P_IP))
239+
lua_pushinteger(L, ip_hdr(skb)->protocol);
240+
else if (skb->protocol == htons(ETH_P_IPV6))
241+
lua_pushinteger(L, ipv6_hdr(skb)->nexthdr);
242+
else
243+
lua_pushnil(L);
244+
return 1;
245+
}
246+
198247
static int luaskb_copy(lua_State *L);
199248

200249
static void luaskb_release(void *private)
@@ -211,18 +260,25 @@ static const luaL_Reg luaskb_lib[] = {
211260
};
212261

213262
static const luaL_Reg luaskb_mt[] = {
214-
{"__gc", lunatik_deleteobject},
215-
{"__len", luaskb_len},
216-
{"ifindex", luaskb_ifindex},
217-
{"vlan", luaskb_vlan},
218-
{"data", luaskb_data},
219-
{"resize", luaskb_resize},
220-
{"checksum", luaskb_checksum},
221-
{"forward", luaskb_forward},
222-
{"copy", luaskb_copy},
263+
{"__gc", lunatik_deleteobject},
264+
{"__len", luaskb_len},
265+
{"ifindex", luaskb_ifindex},
266+
{"vlan", luaskb_vlan},
267+
{"data", luaskb_data},
268+
{"resize", luaskb_resize},
269+
{"checksum", luaskb_checksum},
270+
{"forward", luaskb_forward},
271+
{"copy", luaskb_copy},
272+
{"protocol", luaskb_protocol},
273+
{"proto", luaskb_proto},
274+
{"getmark", luaskb_getmark},
275+
{"getpriority", luaskb_getpriority},
276+
{"setmark", luaskb_setmark},
277+
{"setpriority", luaskb_setpriority},
223278
{NULL, NULL}
224279
};
225280

281+
226282
LUNATIK_OPENER(skb);
227283
static const lunatik_class_t luaskb_class = {
228284
.name = "skb",

0 commit comments

Comments
 (0)