Skip to content

Commit 5d526dd

Browse files
committed
Implementation of put state function
1 parent 9277e14 commit 5d526dd

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ccflags-y += -D_LUNATIK -D_KERNEL -I$(src) -D_CONFIG_FULL_PANIC -DLUNATIK_UNUSED \
1+
ccflags-y += -D_LUNATIK -D_KERNEL -I$(src) -D_CONFIG_FULL_PANIC -DLUNATIK_UNUSED -DDEBUG\
22
-I$(src)/lua -I$(src)/deps/lua-memory/src
33
asflags-y += -D_LUNATIK -D_KERNEL
44

lib/lunatik.c

+15
Original file line numberDiff line numberDiff line change
@@ -810,3 +810,18 @@ int lunatik_getcurralloc(struct lunatik_nl_state *state)
810810
printf("Failed to put attribute to get current alloc of state %s\n", state->name);
811811
return -1;
812812
}
813+
814+
int lunatik_putstate(struct lunatik_nl_state *state)
815+
{
816+
struct nl_msg *msg;
817+
818+
int err = -1;
819+
820+
if ((msg = prepare_message(PUT_STATE, 0)) == NULL)
821+
return err;
822+
823+
if ((err = nl_send_auto(state->control_sock, msg)) < 0)
824+
return err;
825+
826+
return 0;
827+
}

lib/lunatik.h

+2
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,6 @@ int lunatik_datasend(struct lunatik_nl_state *state,
113113

114114
int lunatik_getcurralloc(struct lunatik_nl_state *state);
115115

116+
int lunatik_putstate(struct lunatik_nl_state *state);
117+
116118
#endif /* LUNATIK_H */

lib/lunatik_module.c

+10
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,15 @@ static int lstate_getcurralloc(lua_State *L)
319319
return 1;
320320
}
321321

322+
static int lstate_put(lua_State *L)
323+
{
324+
struct lunatik_nl_state *state = getnlstate(L);
325+
326+
lunatik_putstate(state);
327+
328+
return 0;
329+
}
330+
322331
static const luaL_Reg session_mt[] = {
323332
{"close", lsession_close},
324333
{"getfd", lsession_getfd},
@@ -337,6 +346,7 @@ static const luaL_Reg state_mt[] = {
337346
{"close", lstate_close},
338347
{"send", lstate_datasend},
339348
{"receive", lstate_datareceive},
349+
{"put", lstate_put},
340350
{NULL, NULL}
341351
};
342352

netlink.c

+17
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static int lunatikN_data(struct sk_buff *buff, struct genl_info *info);
5151
static int lunatikN_datainit(struct sk_buff *buff, struct genl_info *info);
5252
static int lunatikN_sendstate(struct sk_buff *buff, struct genl_info *info);
5353
static int lunatikN_getcurralloc(struct sk_buff *buff, struct genl_info *info);
54+
static int lunatikN_putstate(struct sk_buff *buff, struct genl_info *info);
5455

5556
struct nla_policy lunatik_policy[ATTRS_COUNT] = {
5657
[STATE_NAME] = { .type = NLA_STRING },
@@ -123,8 +124,16 @@ static const struct genl_ops l_ops[] = {
123124
.doit = lunatikN_getcurralloc,
124125
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0)
125126
.policy = lunatik_policy
127+
#endif
128+
},
129+
{
130+
.cmd = PUT_STATE,
131+
.doit = lunatikN_putstate,
132+
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0)
133+
.policy = lunatik_policy
126134
#endif
127135
}
136+
128137
};
129138

130139
struct genl_family lunatik_family = {
@@ -714,6 +723,14 @@ static int lunatikN_getcurralloc(struct sk_buff *buff, struct genl_info *info)
714723
return 0;
715724
}
716725

726+
static int lunatikN_putstate(struct sk_buff *buff, struct genl_info *info)
727+
{
728+
struct lunatik_state *s;
729+
pr_debug("Received a PUT_STATE command\n");
730+
731+
return 0;
732+
}
733+
717734
/* Note: Most of the function below is copied from NFLua: https://github.com/cujoai/nflua
718735
* Copyright (C) 2017-2019 CUJO LLC
719736
*

netlink_common.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ enum lunatik_operations {
4444
DATA_INIT,
4545
GET_STATE,
4646
GET_CURRALLOC,
47+
PUT_STATE,
4748
};
4849

4950
enum lunatik_attrs {

0 commit comments

Comments
 (0)