Christian Grabowski Christian Grabowski - 20 days ago 4
C Question

Instantiating BSD jails from C

I have been trying to be able to create BSD jails from an application. Based on the FreeBSD man pages for jail(2) I've come up with:

struct jail _jail;
_jail->version = <jail version>;
_jail->path = "/some/path/";
_jail->hostname = "some-host";
_jail->jailname = "jailname";
_jail->ip4s = <ip value>;
_jail->ip6s = <ip value>;
_jail->ip4 = <ip4 struct>;
_jail->ip6 = <ip6 struct>;
int jid = jail(&jail);

So from this, I was wondering what example values for the ip4, and ip6 fields would look like? Additionally what tool(s) can I use to inspect the jail to ensure that I instantiated them properly? (I'm traditionally a Linux user, so this is uncharted territory for me).

To clarify the fields question, I understand what the in_addr type is in Linux, can I assume it is the same for FreeBSD?


To run arbitrary command in the jail use jexec:

jexec jail ls
jexec jail ps

You can also run a shell inside jail:

jexec jail csh

Or even

jexec jail env -i TERM=$TERM /usr/bin/login -fp root