NAME
frame
—
frame protocol family
SYNOPSIS
pseudo-device af_frame
#include <sys/types.h>
#include <net/frame.h>
DESCRIPTION
The frame
protocol family provides an
interface for sending and receiving low level network interface frames
through the normal socket(2) mechanisms.
The frame
protocol family supports the
SOCK_DGRAM
socket type. Only root may create
frame
protocol family sockets.
frame
protocol family sockets are designed
as an alternative to bpf(4) for handling low data and packet rate communication protocols.
Rather than filtering every frame entering the system before the network
stack, like bpf(4), processing of the frame
protocol
family runs after the built in protocol handlers in the kernel, thus
avoiding the overhead. For this reason, it is not possible to handle IPv4 or
IPv6 packets with frame
protocol sockets because the
kernel network stack consumes them before the receive handling for
frame
sockets is run.
Sockets can be created in the frame
protocol family by using AF_FRAME
as the
domain argument to
socket(2).
The type of interface, as per
<net/if_types.h>
, is
specified as the socket protocol. Currently only
Ethernet interfaces are supported.
Sockets bound to the frame
family use the
following address structure:
#define FRAME_ADDRLEN 8 #define FRAME_DATALEN 32 struct sockaddr_frame { uint8_t sfrm_len; uint8_t sfrm_family; uint16_t sfrm_proto; unsigned int sfrm_ifindex; uint8_t sfrm_addr[FRAME_ADDRLEN]; char sfrm_ifname[IFNAMSIZ]; uint8_t sfrm_data[FRAME_DATALEN]; };
The interface used for transmitting or receiving frames with a
frame
domain socket may be specified by using an
interface index with sfrm_ifindex, or by name with
sfrm_ifname. The use of other struct
sockaddr_frame fields depends on the type of interface.
Ethernet frame sockets
A frame
socket for use with Ethernet
interfaces can be created using IFT_ETHER
as the
protocol argument to
socket(2):
int sock = socket(AF_FRAME, SOCK_DGRAM, IFT_ETHER);
The Ethernet protocol is specified with sfrm_proto in network byte order. Ethernet addresses are specified using the first 6 bytes of sfrm_addr.
Ethernet frame
sockets may receive frames
on all interfaces by specifying 0 for sfrm_ifindex
when using bind(2). Similarly, a “wildcard” local address of all
zeros can be specified in sfrm_addr.
An interface and address must be specified when sending Ethernet frames.
Ethernet sockets support the following
frame
socket options using
IFT_ETHER
as the level
argument with setsockopt(2) and
getsockopt(2):
FRAME_RECVDSTADDR
int- Enable or disable the reception of the Ethernet destination address as a struct ether_addr control message for frames received with recvmsg(2).
FRAME_RECVPRIO
int- Enable or disable the reception of the mbuf packet priority field as an int sized control message for frames received with recvmsg(2).
FRAME_ADD_MEMBERSHIP
struct frame_mreq- Configure an Ethernet interface to enable reception of frames destined to
the specified multicast Ethernet address.
struct frame_mreq { unsigned int fmr_ifindex; uint8_t fmr_addr[FRAME_ADDRLEN]; char fmr_ifname[IFNAMSIZ]; };
An interface must be specified using either fmr_ifindex or fmr_ifname. The multicast Ethernet address is specified in the first 6 bytes of fmr_addr.
FRAME_DEL_MEMBERSHIP
struct frame_mreq- Configure an Ethernet interface to disable reception of frames destined to the specified multicast Ethernet address.
FRAME_SENDPRIO
int- Specify an mbuf priority value between
IF_HDRPRIO_MIN
(0) andIF_HDRPRIO_MAX
(7) for frames sent with the Ethernetframe
socket, orIF_HDRPRIO_PACKET
to use the existing mbuf priority value. The default isIF_HDRPRIO_PACKET
.
EXAMPLES
To receive LLDP frames on the em0 Ethernet interface:
struct sockaddr_frame sfrm = { .sfrm_family = AF_FRAME, .sfrm_ifname = "em0", .sfrm_proto = htons(ETHERTYPE_LLDP), }; struct frame_mreq fmr = { .fmr_ifname = "em0", .fmr_addr = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e }, }; int sock; sock = socket(AF_FRAME, SOCK_DGRAM, IFT_ETHER); if (sock == -1) err(1, "ethernet frame socket"); if (bind(sock, (struct addrinfo *)&sfrm, sizeof(sfrm)) == -1) err(1, "bind"); if (setsockopt(sock, IFT_ETHER, FRAME_ADD_MEMBERSHIP, &fmr, sizeof(fmr)) == -1) err(1, "join lldp multicast group"); for (;;) { socklen_t sfrmlen = sizeof(sfrm); uint8_t frame[2048]; ssize_t rv; rv = recvfrom(sock, frame, sizeof(frame), 0, (struct sockaddr *)&sfrm, &sfrmlen); if (rv == -1) err(1, "lldp recv"); printf("received %zd bytes from %s", rv, ether_ntoa((struct ether_addr *)sfrm->sfrm_addr)); }
SEE ALSO
HISTORY
frame
domain sockets appeared in
OpenBSD 7.7.
AUTHORS
David Gwynne <dlg@openbsd.org>.