Page MenuHomeFreeBSD

Teach ifconfig to attach and run itself in a jail.
ClosedPublic

Authored by nyan_myuji.xyz on Mon, May 22, 7:37 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, May 28, 3:16 PM
Unknown Object (File)
Sat, May 27, 2:28 PM
Unknown Object (File)
Fri, May 26, 6:42 AM
Unknown Object (File)
Wed, May 24, 9:24 AM
Unknown Object (File)
Wed, May 24, 2:40 AM
Unknown Object (File)
Tue, May 23, 8:56 PM
Unknown Object (File)
Tue, May 23, 7:45 PM
Subscribers

Details

Summary

Add -j <jail> flag to ifconfig to allow ifconfig to attach and run inside a
jail. This allow parent to configure network interfaces of its children
even if ifconfig is not available in child's tree (e.g. Linux Jails)

Event: Kitchener-Waterloo Hackathon 202305

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sbin/ifconfig/ifconfig.c
468

The following sounds more idiomatic to me:

jid = jail_getid(optarg);
if (jid == -1)

Perror("1");

if (jail_attach(jid) != 0)

Perror("2");
sbin/ifconfig/ifconfig.c
468

Great! I prefer that too just worry about breaking style.

LGTM. You may want to add a manual page changes as well.

This revision is now accepted and ready to land.Mon, May 22, 8:13 PM

yes let's add the man page in here too

sbin/ifconfig/ifconfig.c
473

Do we want

#else
    Perror("not built with jail support")

or leave j out of options when not #ifdef JAIL?

  • modify man page to refactor the new -j flag
This revision now requires review to proceed.Mon, May 22, 10:23 PM
sbin/ifconfig/ifconfig.8
31

Bump the date. :-)

sbin/ifconfig/ifconfig.c
473

Maybe perror() is easier since going the other way, we also need to have usage() #ifdef'd

If would be perfect if you want to add a simple test under tests/

  • print error and exit if -j specified but ifconfig isn't built with jail support
  • bump manpage date

BTW, I'm not sure if doing jail_attach() in args_parse() is a common or good practice.

Move jail_attach away from args_parse

This revision is now accepted and ready to land.Tue, May 23, 2:35 AM
melifaro added a subscriber: melifaro.
melifaro added inline comments.
sbin/ifconfig/ifconfig.c
443

Nit: this is not needed, args is zeroed by default.

  • remove explicit initialization
This revision now requires review to proceed.Tue, May 23, 7:43 PM
This revision is now accepted and ready to land.Tue, May 23, 7:45 PM

It would be nice to have something similar for route. Setting up network state for containers with external connectivity also needs some way of setting a default route. For podman, I ended up nesting the container jail inside another jail where I can safely run ifconfig and route without requiring their presence inside the container (or trusting the container's binaries if they are present).