Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177721851
D61725.1795130222.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
D61725.1795130222.diff
View Options
diff --git a/usr.sbin/arp/Makefile b/usr.sbin/arp/Makefile
--- a/usr.sbin/arp/Makefile
+++ b/usr.sbin/arp/Makefile
@@ -14,6 +14,11 @@
LIBADD= xo
+.if ${MK_JAIL} != "no"
+CFLAGS+=-DJAIL
+LIBADD+= jail
+.endif
+
WARNS?= 3
.include <bsd.prog.mk>
diff --git a/usr.sbin/arp/Makefile.depend b/usr.sbin/arp/Makefile.depend
--- a/usr.sbin/arp/Makefile.depend
+++ b/usr.sbin/arp/Makefile.depend
@@ -7,6 +7,7 @@
lib/${CSU_DIR} \
lib/libc \
lib/libcompiler_rt \
+ lib/libjail \
lib/libxo/libxo \
diff --git a/usr.sbin/arp/arp.8 b/usr.sbin/arp/arp.8
--- a/usr.sbin/arp/arp.8
+++ b/usr.sbin/arp/arp.8
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd July 16, 2025
+.Dd November 18, 2026
.Dt ARP 8
.Os
.Sh NAME
@@ -34,31 +34,38 @@
.Sh SYNOPSIS
.Nm
.Op Fl -libxo Ar options
+.Op Fl j Ar jail
.Op Fl n
.Op Fl i Ar interface
.Ar hostname
.Nm
.Op Fl -libxo Ar options
+.Op Fl j Ar jail
.Op Fl n
.Op Fl i Ar interface
.Fl a
.Nm
+.Op Fl j Ar jail
.Fl d Ar hostname
.Nm
+.Op Fl j Ar jail
.Fl d
.Op Fl i Ar interface
.Fl a
.Nm
+.Op Fl j Ar jail
.Fl s Ar hostname ether_addr
.Op Cm temp
.Op Cm blackhole No \&| Cm reject
.Op Cm pub
.Nm
+.Op Fl j Ar jail
.Fl S Ar hostname ether_addr
.Op Cm temp
.Op Cm blackhole No \&| Cm reject
.Op Cm pub
.Nm
+.Op Fl j Ar jail
.Fl f Ar filename
.Sh DESCRIPTION
The
@@ -107,6 +114,19 @@
.Ar interface .
Applicable only to the following operations:
display one, display all, delete all.
+.It Fl j Ar jail
+Attach to the jail named by
+.Ar jail ,
+a jail name or JID, before performing the operation,
+so that it applies to the
+.Tn ARP
+table of that jail's virtual network stack.
+.Pp
+Host names are resolved inside the jail, using its name service
+configuration and network stack.
+Use numeric addresses and the
+.Fl n
+flag if the jail cannot resolve names.
.It Fl n
Show network addresses as numbers (normally
.Nm
@@ -179,6 +199,11 @@
A
.Ql #
character will mark the rest of the line as a comment.
+.Pp
+If the
+.Fl j Ar jail
+option is specified, the file will be opened before attaching to the jail and
+then be processed inside the jail.
.El
.Sh SEE ALSO
.Xr inet 3 ,
@@ -186,6 +211,7 @@
.Xr xo_options 7 ,
.Xr arp 4 ,
.Xr ifconfig 8 ,
+.Xr jail 8 ,
.Xr ndp 8
.Sh HISTORY
The
diff --git a/usr.sbin/arp/arp.c b/usr.sbin/arp/arp.c
--- a/usr.sbin/arp/arp.c
+++ b/usr.sbin/arp/arp.c
@@ -42,6 +42,7 @@
#include <sys/sockio.h>
#include <sys/sysctl.h>
#include <sys/ioctl.h>
+#include <sys/jail.h>
#include <sys/time.h>
#include <net/if.h>
@@ -66,6 +67,9 @@
#include <strings.h>
#include <unistd.h>
#include <ifaddrs.h>
+#ifdef JAIL
+#include <jail.h>
+#endif
#include <libxo/xo.h>
#include "arp.h"
@@ -78,7 +82,7 @@
static void usage(void) __dead2;
static int set(int argc, char **argv);
static int get(char *host);
-static int file(char *name);
+static int file(FILE *fp);
static struct rt_msghdr *rtmsg(int cmd,
struct sockaddr_in *dst, struct sockaddr_dl *sdl);
static int set_rtsock(struct sockaddr_in *dst, struct sockaddr_dl *sdl_m,
@@ -104,12 +108,17 @@
{
int ch, func = 0;
int rtn = 0;
+ FILE *fp = NULL;
+#ifdef JAIL
+ char *jail_name = NULL;
+ int jid;
+#endif
argc = xo_parse_args(argc, argv);
if (argc < 0)
exit(1);
- while ((ch = getopt(argc, argv, "andfsSi:")) != -1)
+ while ((ch = getopt(argc, argv, "andfsSi:j:")) != -1)
switch(ch) {
case 'a':
opts.aflag = true;
@@ -132,6 +141,13 @@
case 'i':
opts.rifname = optarg;
break;
+ case 'j':
+#ifdef JAIL
+ jail_name = optarg;
+#else
+ xo_errx(1, "Jail support is not compiled in");
+#endif
+ break;
case '?':
default:
usage();
@@ -139,6 +155,24 @@
argc -= optind;
argv += optind;
+ /* The file is named relative to the caller, not to the jail. */
+ if (func == F_FILESET) {
+ if (argc != 1)
+ usage();
+ if ((fp = fopen(argv[0], "r")) == NULL)
+ xo_err(1, "cannot open %s", argv[0]);
+ }
+
+#ifdef JAIL
+ if (jail_name != NULL) {
+ jid = jail_getid(jail_name);
+ if (jid == -1)
+ xo_errx(1, "%s", jail_errmsg);
+ if (jail_attach(jid) != 0)
+ xo_err(1, "cannot attach to jail %s", jail_name);
+ }
+#endif
+
if (!func)
func = F_GET;
if (opts.rifname) {
@@ -197,9 +231,7 @@
}
break;
case F_FILESET:
- if (argc != 1)
- usage();
- rtn = file(argv[0]);
+ rtn = file(fp);
break;
}
@@ -213,14 +245,11 @@
* Process a file to set standard arp entries
*/
static int
-file(char *name)
+file(FILE *fp)
{
- FILE *fp;
int i, retval;
char line[100], arg[5][50], *args[5], *p;
- if ((fp = fopen(name, "r")) == NULL)
- xo_err(1, "cannot open %s", name);
args[0] = &arg[0][0];
args[1] = &arg[1][0];
args[2] = &arg[2][0];
@@ -726,14 +755,16 @@
static void
usage(void)
{
- xo_error("%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
- "usage: arp [-n] [-i interface] hostname",
- " arp [-n] [-i interface] -a",
- " arp -d hostname [pub]",
- " arp -d [-i interface] -a",
- " arp -s hostname ether_addr [temp] [reject | blackhole] [pub [only]]",
- " arp -S hostname ether_addr [temp] [reject | blackhole] [pub [only]]",
- " arp -f filename");
+ xo_error("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
+ "usage: arp [-j jail] [-n] [-i interface] hostname",
+ " arp [-j jail] [-n] [-i interface] -a",
+ " arp [-j jail] -d hostname [pub]",
+ " arp [-j jail] -d [-i interface] -a",
+ " arp [-j jail] -s hostname ether_addr [temp] [reject | blackhole]",
+ " [pub [only]]",
+ " arp [-j jail] -S hostname ether_addr [temp] [reject | blackhole]",
+ " [pub [only]]",
+ " arp [-j jail] -f filename");
exit(1);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 19, 11:17 PM (6 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41853168
Default Alt Text
D61725.1795130222.diff (5 KB)
Attached To
Mode
D61725: arp: Teach arp to attach and run itself in a jail
Attached
Detach File
Event Timeline