Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion include/sephix/net.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#ifndef __SEPHIX__NET_H
#define __SEPHIX__NET_H

#include <netlink/cache.h>
#include <netlink/handlers.h>
#include "sandbox.h"

int
net__set_if_updown(struct sandbox_t *sandbox, const char *ifname, int up);

int
net__set_link_updown(const char *ifname, int up);
net__link_master_if(struct sandbox_t *sandbox,
const char *master_if_name,
const char *ip,
int default_gw);

#endif
20 changes: 20 additions & 0 deletions include/sephix/netctx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef __SEPHIX__NETCTX_H
#define __SEPHIX__NETCTX_H

struct netctx {
struct nl_sock *sock;
struct nl_cache *link_cache;
struct nl_cache *addr_cache;
struct nl_cache *route_cache;
};

struct netctx *
netctx__create();

void
netctx__refill_cache(struct netctx *ctx);

void
netctx__free(struct netctx *ctx);

#endif
10 changes: 9 additions & 1 deletion include/sephix/sandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@
#define __SEPHIX__SANDBOX_H

#include "profile.h"
#include "sephix/netctx.h"

#include <sys/types.h>

struct sandbox_t {
struct netctx *master_ctx;
struct netctx *slave_ctx;

int clone_flags;

pid_t master_pid;
pid_t slave_pid;

gid_t gid;
uid_t uid;
gid_t gid;

struct profile_t *profile;
struct profile_data_t *prof_dt;

int master_netns_fd;
int slave_netns_fd;

int ruleset_fd; // landlock

const char *name;
Expand Down
8 changes: 8 additions & 0 deletions src/sephix/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "config.h"
#include "confuse.h"
#include "euid.h"
#include "sephix/net.h"
#include "sephix/sandbox.h"
#include "sephix_build_config.h"
#include "util.h"
Expand Down Expand Up @@ -68,6 +69,8 @@ main(int argc, char **argv)

int i, j;

int netns_fd;

char *profile_name = NULL;
char *runtime_dir = NULL;

Expand All @@ -84,6 +87,9 @@ main(int argc, char **argv)
static struct profile_t profile = {0};
static struct profile_data_t *prof_dt;

netns_fd = open("/proc/self/ns/net", O_RDONLY);
if (netns_fd < 0) DIE_PERROR("open");

prof_dt = profile_data_t__create();
if (prof_dt == NULL) DIE_LOG_ERROR("profile_data_t__create");

Expand Down Expand Up @@ -176,12 +182,14 @@ main(int argc, char **argv)
}

struct sandbox_t sandbox = {
.master_ctx = netctx__create(),
.master_pid = getpid(),
.gid = getgid(),
.uid = getuid(),
.name = NULL,
.profile = &profile,
.prof_dt = prof_dt,
.master_netns_fd = netns_fd,
.runtime_dir = runtime_dir,
.exec_argc = exec_argc,
.exec_argv = exec_argv,
Expand Down
Loading