The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Functions | Variables
ethernet.c File Reference

Functions to parse and construct ethernet headers. More...

#include "ethernet.h"
#include <string.h>
#include <arpa/inet.h>
#include <freeradius-devel/io/proto.h>
+ Include dependency graph for ethernet.c:

Go to the source code of this file.

Functions

static ssize_t fr_ethernet_decode (void *proto_ctx, uint8_t const *data, size_t data_len)
 Decodes an ethernet header with up to two levels of VLAN nesting. More...
 
static ssize_t fr_ethernet_encode (void *proto_ctx, uint8_t *data, size_t data_len)
 Encodes an ethernet header and up to two levels of VLAN nesting. More...
 
static int fr_ethernet_get_option (fr_value_box_t *out, void const *proto_ctx, fr_proto_opt_group_t group, int opt)
 Retrieve an option value from the proto_ctx. More...
 
static void fr_ethernet_invert (void *proto_ctx)
 Inverts addresses, so that a decoder proto_ctx can be used for encoding. More...
 
static int fr_ethernet_set_option (void *proto_ctx, fr_proto_opt_group_t group, int opt, fr_value_box_t *in)
 Set an option in the proto_ctx. More...
 

Variables

fr_proto_lib_t const libfreeradius_ethernet
 

Detailed Description

Functions to parse and construct ethernet headers.

Id
45774a04e8cb082659d1382098d822e65fc40410

Definition in file ethernet.c.

Function Documentation

◆ fr_ethernet_decode()

static ssize_t fr_ethernet_decode ( void *  proto_ctx,
uint8_t const *  data,
size_t  data_len 
)
static

Decodes an ethernet header with up to two levels of VLAN nesting.

Technically this should be a .1Q protocol, but because of how .1Q subsumes the ether_type field, it's just easier to munge it together with the ethernet decoder.

Parameters
[out]proto_ctxHeader information extracted from the ethernet frame, and any additional VLAN tags discovered. Must point to memory of the size indicated by the fr_proto_lib_t struct exported by this library.
[in]dataStart of packet data.
[in]data_lenof the data.
Returns
  • >0 Length of the header.
  • <=0 on failure.

Definition at line 44 of file ethernet.c.

◆ fr_ethernet_encode()

static ssize_t fr_ethernet_encode ( void *  proto_ctx,
uint8_t data,
size_t  data_len 
)
static

Encodes an ethernet header and up to two levels of VLAN nesting.

Parameters
[in]proto_ctxproduced by fr_ethernet_decode, or by the code creating a new packet.
[out]dataWhere to write output data.
[in]data_lenLength of the output buffer.
Returns
  • >0 The length of data written to the buffer.
  • 0 an error occurred.
  • <0 The amount of buffer space we would have needed (as a negative integer).

Definition at line 148 of file ethernet.c.

◆ fr_ethernet_get_option()

static int fr_ethernet_get_option ( fr_value_box_t out,
void const *  proto_ctx,
fr_proto_opt_group_t  group,
int  opt 
)
static

Retrieve an option value from the proto_ctx.

Parameters
[out]outvalue box to place option value into.
[in]proto_ctxto retrieve value from.
[in]groupOption group. Which collection of options to query.
[in]optOption to retrieve.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 260 of file ethernet.c.

+ Here is the call graph for this function:

◆ fr_ethernet_invert()

static void fr_ethernet_invert ( void *  proto_ctx)
static

Inverts addresses, so that a decoder proto_ctx can be used for encoding.

Parameters
[in]proto_ctxcreated by the user or decoder.

Definition at line 237 of file ethernet.c.

◆ fr_ethernet_set_option()

static int fr_ethernet_set_option ( void *  proto_ctx,
fr_proto_opt_group_t  group,
int  opt,
fr_value_box_t in 
)
static

Set an option in the proto_ctx.

Parameters
[in]proto_ctxto set value in.
[in]groupOption group. Which collection of options opt exists in.
[in]optOption to set.
[in]invalue to set.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 333 of file ethernet.c.

+ Here is the call graph for this function:

Variable Documentation

◆ libfreeradius_ethernet

fr_proto_lib_t const libfreeradius_ethernet
Initial value:
= {
.name = "ethernet",
.decode = fr_ethernet_decode,
.encode = fr_ethernet_encode,
.invert = fr_ethernet_invert,
.get_option = fr_ethernet_get_option,
.set_option = fr_ethernet_set_option
}
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:63
static ssize_t fr_ethernet_decode(void *proto_ctx, uint8_t const *data, size_t data_len)
Decodes an ethernet header with up to two levels of VLAN nesting.
Definition: ethernet.c:44
static int fr_ethernet_get_option(fr_value_box_t *out, void const *proto_ctx, fr_proto_opt_group_t group, int opt)
Retrieve an option value from the proto_ctx.
Definition: ethernet.c:260
static ssize_t fr_ethernet_encode(void *proto_ctx, uint8_t *data, size_t data_len)
Encodes an ethernet header and up to two levels of VLAN nesting.
Definition: ethernet.c:148
static void fr_ethernet_invert(void *proto_ctx)
Inverts addresses, so that a decoder proto_ctx can be used for encoding.
Definition: ethernet.c:237
static int fr_ethernet_set_option(void *proto_ctx, fr_proto_opt_group_t group, int opt, fr_value_box_t *in)
Set an option in the proto_ctx.
Definition: ethernet.c:333
@ PROTO_OPT_GROUP_L2
Generic layer 2 options.
Definition: proto.h:39
@ PROTO_OPT_GROUP_CUSTOM
Custom options exported by the library.
Definition: proto.h:37

Definition at line 403 of file ethernet.c.