xref: /aosp_15_r20/external/libpcap/doc/README.macos (revision 8b26181f966a6af5cf6981a6f474313de533bb28)
1*8b26181fSAndroid Build Coastguard WorkerAs with other systems using BPF, macOS allows users with read access to
2*8b26181fSAndroid Build Coastguard Workerthe BPF devices to capture packets with libpcap and allows users with
3*8b26181fSAndroid Build Coastguard Workerwrite access to the BPF devices to send packets with libpcap.
4*8b26181fSAndroid Build Coastguard Worker
5*8b26181fSAndroid Build Coastguard WorkerOn some systems that use BPF, the BPF devices live on the root file
6*8b26181fSAndroid Build Coastguard Workersystem, and the permissions and/or ownership on those devices can be
7*8b26181fSAndroid Build Coastguard Workerchanged to give users other than root permission to read or write those
8*8b26181fSAndroid Build Coastguard Workerdevices.
9*8b26181fSAndroid Build Coastguard Worker
10*8b26181fSAndroid Build Coastguard WorkerOn newer versions of FreeBSD, the BPF devices live on devfs, and devfs
11*8b26181fSAndroid Build Coastguard Workercan be configured to set the permissions and/or ownership of those
12*8b26181fSAndroid Build Coastguard Workerdevices to give users other than root permission to read or write those
13*8b26181fSAndroid Build Coastguard Workerdevices.
14*8b26181fSAndroid Build Coastguard Worker
15*8b26181fSAndroid Build Coastguard WorkerOn macOS, the BPF devices live on devfs, but the macOS version of devfs
16*8b26181fSAndroid Build Coastguard Workeris based on an older (non-default) FreeBSD devfs, and that version of
17*8b26181fSAndroid Build Coastguard Workerdevfs cannot be configured to set the permissions and/or ownership of
18*8b26181fSAndroid Build Coastguard Workerthose devices.
19*8b26181fSAndroid Build Coastguard Worker
20*8b26181fSAndroid Build Coastguard WorkerTherefore, we supply:
21*8b26181fSAndroid Build Coastguard Worker
22*8b26181fSAndroid Build Coastguard Worker	a "startup item" for older versions of macOS;
23*8b26181fSAndroid Build Coastguard Worker
24*8b26181fSAndroid Build Coastguard Worker	a launchd daemon for Tiger and later versions of macOS;
25*8b26181fSAndroid Build Coastguard Worker
26*8b26181fSAndroid Build Coastguard WorkerBoth of them will change the ownership of the BPF devices so that the
27*8b26181fSAndroid Build Coastguard Worker"admin" group owns them, and will change the permission of the BPF
28*8b26181fSAndroid Build Coastguard Workerdevices to rw-rw----, so that all users in the "admin" group - i.e., all
29*8b26181fSAndroid Build Coastguard Workerusers with "Allow user to administer this computer" turned on - have
30*8b26181fSAndroid Build Coastguard Workerboth read and write access to them.
31*8b26181fSAndroid Build Coastguard Worker
32*8b26181fSAndroid Build Coastguard WorkerThe startup item is in the ChmodBPF directory in the source tree.  A
33*8b26181fSAndroid Build Coastguard Worker/Library/StartupItems directory should be created if it doesn't already
34*8b26181fSAndroid Build Coastguard Workerexist, and the ChmodBPF directory should be copied to the
35*8b26181fSAndroid Build Coastguard Worker/Library/StartupItems directory (copy the entire directory, so that
36*8b26181fSAndroid Build Coastguard Workerthere's a /Library/StartupItems/ChmodBPF directory, containing all the
37*8b26181fSAndroid Build Coastguard Workerfiles in the source tree's ChmodBPF directory; don't copy the individual
38*8b26181fSAndroid Build Coastguard Workeritems in that directory to /Library/StartupItems).  The ChmodBPF
39*8b26181fSAndroid Build Coastguard Workerdirectory, and all files under it, must be owned by root.  Installing
40*8b26181fSAndroid Build Coastguard Workerthe files won't immediately cause the startup item to be executed; it
41*8b26181fSAndroid Build Coastguard Workerwill be executed on the next reboot.  To change the permissions before
42*8b26181fSAndroid Build Coastguard Workerthe reboot, run
43*8b26181fSAndroid Build Coastguard Worker
44*8b26181fSAndroid Build Coastguard Worker	sudo SystemStarter start ChmodBPF
45*8b26181fSAndroid Build Coastguard Worker
46*8b26181fSAndroid Build Coastguard WorkerThe launchd daemon is the chmod_bpf script, plus the
47*8b26181fSAndroid Build Coastguard Workerorg.tcpdump.chmod_bpf.plist launchd plist file.  chmod_bpf should be
48*8b26181fSAndroid Build Coastguard Workerinstalled in /usr/local/bin/chmod_bpf, and org.tcpdump.chmod_bpf.plist
49*8b26181fSAndroid Build Coastguard Workershould be installed in /Library/LaunchDaemons.  chmod_bpf, and
50*8b26181fSAndroid Build Coastguard Workerorg.tcpdump.chmod_bpf.plist, must be owned by root.  Installing the
51*8b26181fSAndroid Build Coastguard Workerscript and plist file won't immediately cause the script to be executed;
52*8b26181fSAndroid Build Coastguard Workerit will be executed on the next reboot.  To change the permissions
53*8b26181fSAndroid Build Coastguard Workerbefore the reboot, run
54*8b26181fSAndroid Build Coastguard Worker
55*8b26181fSAndroid Build Coastguard Worker	sudo /usr/local/bin/chmod_bpf
56*8b26181fSAndroid Build Coastguard Worker
57*8b26181fSAndroid Build Coastguard Workeror
58*8b26181fSAndroid Build Coastguard Worker
59*8b26181fSAndroid Build Coastguard Worker	sudo launchctl load /Library/LaunchDaemons/org.tcpdump.chmod_bpf.plist
60*8b26181fSAndroid Build Coastguard Worker
61*8b26181fSAndroid Build Coastguard WorkerIf you want to give a particular user permission to access the BPF
62*8b26181fSAndroid Build Coastguard Workerdevices, rather than giving all administrative users permission to
63*8b26181fSAndroid Build Coastguard Workeraccess them, you can have the ChmodBPF/ChmodBPF script change the
64*8b26181fSAndroid Build Coastguard Workerownership of /dev/bpf* without changing the permissions.  If you want to
65*8b26181fSAndroid Build Coastguard Workergive a particular user permission to read and write the BPF devices and
66*8b26181fSAndroid Build Coastguard Workergive the administrative users permission to read but not write the BPF
67*8b26181fSAndroid Build Coastguard Workerdevices, you can have the script change the owner to that user, the
68*8b26181fSAndroid Build Coastguard Workergroup to "admin", and the permissions to rw-r-----.  Other possibilities
69*8b26181fSAndroid Build Coastguard Workerare left as an exercise for the reader.
70*8b26181fSAndroid Build Coastguard Worker
71*8b26181fSAndroid Build Coastguard Worker(NOTE: due to a bug in Snow Leopard, if you change the permissions not
72*8b26181fSAndroid Build Coastguard Workerto grant write permission to everybody who should be allowed to capture
73*8b26181fSAndroid Build Coastguard Workertraffic, non-root users who cannot open the BPF devices for writing will
74*8b26181fSAndroid Build Coastguard Workernot be able to capture outgoing packets.)
75