Skip to content

Commit

Permalink
Implementation of put state function
Browse files Browse the repository at this point in the history
  • Loading branch information
MatheusNtg committed Oct 17, 2020
1 parent 9277e14 commit 5d526dd
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ccflags-y += -D_LUNATIK -D_KERNEL -I$(src) -D_CONFIG_FULL_PANIC -DLUNATIK_UNUSED \
ccflags-y += -D_LUNATIK -D_KERNEL -I$(src) -D_CONFIG_FULL_PANIC -DLUNATIK_UNUSED -DDEBUG\
-I$(src)/lua -I$(src)/deps/lua-memory/src
asflags-y += -D_LUNATIK -D_KERNEL

Expand Down
15 changes: 15 additions & 0 deletions lib/lunatik.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,3 +810,18 @@ int lunatik_getcurralloc(struct lunatik_nl_state *state)
printf("Failed to put attribute to get current alloc of state %s\n", state->name);
return -1;
}

int lunatik_putstate(struct lunatik_nl_state *state)
{
struct nl_msg *msg;

int err = -1;

if ((msg = prepare_message(PUT_STATE, 0)) == NULL)
return err;

if ((err = nl_send_auto(state->control_sock, msg)) < 0)
return err;

return 0;
}
2 changes: 2 additions & 0 deletions lib/lunatik.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,6 @@ int lunatik_datasend(struct lunatik_nl_state *state,

int lunatik_getcurralloc(struct lunatik_nl_state *state);

int lunatik_putstate(struct lunatik_nl_state *state);

#endif /* LUNATIK_H */
10 changes: 10 additions & 0 deletions lib/lunatik_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@ static int lstate_getcurralloc(lua_State *L)
return 1;
}

static int lstate_put(lua_State *L)
{
struct lunatik_nl_state *state = getnlstate(L);

lunatik_putstate(state);

return 0;
}

static const luaL_Reg session_mt[] = {
{"close", lsession_close},
{"getfd", lsession_getfd},
Expand All @@ -337,6 +346,7 @@ static const luaL_Reg state_mt[] = {
{"close", lstate_close},
{"send", lstate_datasend},
{"receive", lstate_datareceive},
{"put", lstate_put},
{NULL, NULL}
};

Expand Down
17 changes: 17 additions & 0 deletions netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static int lunatikN_data(struct sk_buff *buff, struct genl_info *info);
static int lunatikN_datainit(struct sk_buff *buff, struct genl_info *info);
static int lunatikN_sendstate(struct sk_buff *buff, struct genl_info *info);
static int lunatikN_getcurralloc(struct sk_buff *buff, struct genl_info *info);
static int lunatikN_putstate(struct sk_buff *buff, struct genl_info *info);

struct nla_policy lunatik_policy[ATTRS_COUNT] = {
[STATE_NAME] = { .type = NLA_STRING },
Expand Down Expand Up @@ -123,8 +124,16 @@ static const struct genl_ops l_ops[] = {
.doit = lunatikN_getcurralloc,
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0)
.policy = lunatik_policy
#endif
},
{
.cmd = PUT_STATE,
.doit = lunatikN_putstate,
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0)
.policy = lunatik_policy
#endif
}

};

struct genl_family lunatik_family = {
Expand Down Expand Up @@ -714,6 +723,14 @@ static int lunatikN_getcurralloc(struct sk_buff *buff, struct genl_info *info)
return 0;
}

static int lunatikN_putstate(struct sk_buff *buff, struct genl_info *info)
{
struct lunatik_state *s;
pr_debug("Received a PUT_STATE command\n");

return 0;
}

/* Note: Most of the function below is copied from NFLua: https://github.com/cujoai/nflua
* Copyright (C) 2017-2019 CUJO LLC
*
Expand Down
1 change: 1 addition & 0 deletions netlink_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ enum lunatik_operations {
DATA_INIT,
GET_STATE,
GET_CURRALLOC,
PUT_STATE,
};

enum lunatik_attrs {
Expand Down

0 comments on commit 5d526dd

Please sign in to comment.