23 #include <freeradius-devel/radiusd.h>
24 #include <freeradius-devel/protocol.h>
25 #include <freeradius-devel/modules.h>
26 #include <freeradius-devel/process.h>
27 #include <freeradius-devel/rad_assert.h>
28 #include <freeradius-devel/pcap.h>
29 #include <net/if_arp.h>
55 struct arphdr const *arp;
60 p = (
const uint8_t *) arp;
67 len -= (p - packet->
data);
69 for (i = 0; i < len; i++) {
70 if ((i & 0x0f) == 0) printf(
"%04zx: ", i);
71 printf(
"%02x ", p[i]);
72 if ((i & 0x0f) == 0x0f) printf(
"\r\n");
99 pcap_t *handle = sock->
lsock.pcap->handle;
102 struct pcap_pkthdr *header;
108 ret = pcap_next_ex(handle, &header, &data);
110 DEBUG(
"No packet retrieved from pcap.");
115 ERROR(
"Error requesting next packet, got (%i): %s", ret, pcap_geterr(handle));
130 if (header->caplen < (link_len +
sizeof(*arp))) {
131 ERROR(
"Packet too small, we require at least %zu bytes, got %i bytes",
132 link_len +
sizeof(*arp), header->caplen);
139 if (ntohs(arp->
htype) != ARPHRD_ETHER)
return 0;
141 if (ntohs(arp->
ptype) != 0x0800)
return 0;
145 if (arp->
plen != 4)
return 0;
148 if (!packet)
return 0;
151 packet->
data_len = header->caplen - link_len;
152 packet->
data = talloc_memdup(packet, arp, packet->
data_len);
153 talloc_set_type(packet->
data, uint8_t);
183 {
"ARP-Hardware-Format", 2 },
184 {
"ARP-Protocol-Format", 2 },
185 {
"ARP-Hardware-Address-Length", 1 },
186 {
"ARP-Protocol-Address-Length", 1 },
187 {
"ARP-Operation", 2 },
188 {
"ARP-Sender-Hardware-Address", 6 },
189 {
"ARP-Sender-Protocol-Address", 4 },
190 {
"ARP-Target-Hardware-Address", 6 },
191 {
"ARP-Target-Protocol-Address", 4 },
207 for (i = 0, p = (uint8_t
const *) arp; header_names[i].
name != NULL; p += header_names[i].
len, i++) {
214 .original = request->
packet
222 header_names[i].
len, &decoder_ctx);
224 RDEBUG(
"Failed decoding %s: %s",
264 sock->
lsock.pcap_type = PCAP_INTERFACE_IN;
273 if (rcode != 0)
return rcode;
285 memset(client, 0,
sizeof(*client));
uint8_t spa[4]
Sender protocol address.
struct arp_decode_t arp_decode_t
char const * nas_type
Type of client (arbitrary).
int common_socket_parse(CONF_SECTION *cs, rad_listen_t *this)
void common_packet_debug(REQUEST *request, RADIUS_PACKET *packet, bool received)
static int arp_socket_send(UNUSED rad_listen_t *listener, UNUSED REQUEST *request)
uint8_t prefix
Prefix length - Between 0-32 for IPv4 and 0-128 for IPv6.
rlm_rcode_t process_post_auth(int type, REQUEST *request)
uint8_t op
1 - Request, 2 - Reply.
static const arp_decode_t header_names[]
static int arp_socket_print(const rad_listen_t *this, char *buffer, size_t bufsize)
ssize_t fr_link_layer_offset(uint8_t const *data, size_t len, int link_layer)
Returns the length of the link layer header.
void cf_pair_add(CONF_SECTION *parent, CONF_PAIR *cp)
Add a configuration pair to a section.
VALUE_PAIR * vps
Result of decoding the packet into VALUE_PAIRs.
char const * secret
Secret PSK.
VALUE_PAIR * fr_cursor_init(vp_cursor_t *cursor, VALUE_PAIR *const *node)
Setup a cursor to iterate over attribute pairs.
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
static int arp_socket_parse(CONF_SECTION *cs, rad_listen_t *this)
struct arp_over_ether arp_over_ether_t
uint8_t * data
Packet data (body).
static void arp_socket_free(rad_listen_t *this)
uint16_t dst_port
DST Port of packet.
Abstraction to allow iterating over different configurations of VALUE_PAIRs.
ssize_t fr_radius_decode_pair_value(TALLOC_CTX *ctx, vp_cursor_t *cursor, fr_dict_attr_t const *parent, uint8_t const *data, size_t const attr_len, size_t const packet_len, void *decoder_ctx)
Create any kind of VP from the attribute contents.
uint8_t plen
Length of protocol address.
void fr_pair_add(VALUE_PAIR **head, VALUE_PAIR *vp)
Add a VP to the end of the list.
union fr_ipaddr_t::@1 ipaddr
fr_ipaddr_t ipaddr
IPv4/IPv6 address of the host.
int common_socket_open(CONF_SECTION *cs, rad_listen_t *this)
Stores an attribute, a value and various bits of other data.
void void cf_log_err_cs(CONF_SECTION const *cs, char const *fmt,...) CC_HINT(format(printf
uint8_t hlen
Length of hardware address.
Configuration AVP similar to a VALUE_PAIR.
char const * fr_strerror(void)
Get the last library error.
uint8_t sha[ETHER_ADDR_LEN]
sender hardware address.
uint16_t ptype
Format of protocol address.
int request_receive(TALLOC_CTX *ctx, rad_listen_t *listener, RADIUS_PACKET *packet, RADCLIENT *client, RAD_REQUEST_FUNP fun)
CONF_PAIR * cf_pair_alloc(CONF_SECTION *parent, char const *attr, char const *value, FR_TOKEN op, FR_TOKEN lhs_type, FR_TOKEN rhs_type)
Allocate a CONF_PAIR.
struct arp_socket_t arp_socket_t
Describes a host allowed to send packets to the server.
uint8_t tha[ETHER_ADDR_LEN]
Target hardware address.
void fr_radius_free(RADIUS_PACKET **)
Free a RADIUS_PACKET.
static int arp_socket_encode(UNUSED rad_listen_t *listener, UNUSED REQUEST *request)
size_t data_len
Length of packet data.
RADIUS_PACKET * packet
Incoming request.
static const char * arp_pcap_filter_builder(UNUSED rad_listen_t *this)
Build PCAP filter string to pass to libpcap Will be called by init_pcap.
uint16_t htype
Format of hardware address.
static int arp_socket_recv(rad_listen_t *listener)
char const * longname
Client identifier.
uint64_t magic
Used to validate loaded library.
RADIUS_PACKET const * packet
uint8_t tpa[4]
Target protocol address.
char * talloc_typed_strdup(void const *t, char const *p)
Call talloc strdup, setting the type on the new chunk correctly.
static int arp_process(REQUEST *request)
char const * shortname
Client nickname.
static int arp_socket_decode(UNUSED rad_listen_t *listener, REQUEST *request)
fr_dict_attr_t const * fr_dict_attr_by_name(fr_dict_t *dict, char const *attr)
Locate a fr_dict_attr_t by its name.