The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Enumerations | Functions | Variables
radsnmp.c File Reference
#include <freeradius-devel/util/conf.h>
#include <freeradius-devel/util/udp.h>
#include <freeradius-devel/util/syserror.h>
#include <freeradius-devel/util/atexit.h>
#include <freeradius-devel/radius/radius.h>
#include <freeradius-devel/radius/list.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/uio.h>
#include <assert.h>
+ Include dependency graph for radsnmp.c:

Go to the source code of this file.

Data Structures

struct  radsnmp_conf_t
 

Macros

#define DEBUG(fmt, ...)   if (fr_debug_lvl >= L_DBG_LVL_1) fr_log(&default_log, L_DBG, __FILE__, __LINE__, "radsnmp (debug): " fmt, ## __VA_ARGS__)
 
#define DEBUG2(fmt, ...)   if (fr_debug_lvl >= L_DBG_LVL_2) fr_log(&default_log, L_DBG, __FILE__, __LINE__, "radsnmp (debug): " fmt, ## __VA_ARGS__)
 
#define ERROR(fmt, ...)   fr_log(&default_log, L_DBG, __FILE__, __LINE__, "radsnmp (error): " fmt, ## __VA_ARGS__)
 
#define NEXT_LINE(_line, _buffer)
 
#define RESPOND_STATIC(_cmd)
 

Enumerations

enum  radsnmp_command_t {
  RADSNMP_UNKNOWN = -1 ,
  RADSNMP_PING = 0 ,
  RADSNMP_GET ,
  RADSNMP_GETNEXT ,
  RADSNMP_SET ,
  RADSNMP_EXIT
}
 

Functions

int main (int argc, char **argv)
 
static fr_packet_tradsnmp_alloc (radsnmp_conf_t *conf, int fd)
 Allocate a new request using values from radsnmp config. More...
 
static int radsnmp_get_response (int fd, fr_dict_attr_t const *root, fr_dict_attr_t const *type, fr_pair_list_t *head)
 Write the result of a get or getnext operation back to net-snmp. More...
 
static ssize_t radsnmp_pair_from_oid (TALLOC_CTX *ctx, radsnmp_conf_t *conf, fr_dcursor_t *cursor, char const *oid, int type, char const *value)
 Builds attribute representing OID string and adds 'index' attributes where required. More...
 
static int radsnmp_send_recv (radsnmp_conf_t *conf, int fd)
 
static int radsnmp_set_response (int fd, fr_dict_attr_t const *error, fr_pair_list_t *head)
 Write the result of a set operation back to net-snmp. More...
 
static void rs_signal_stop (UNUSED int sig)
 
static NEVER_RETURNS void usage (void)
 

Variables

static fr_dict_attr_t const * attr_extended_attribute_1
 
static fr_dict_attr_t const * attr_freeradius_snmp_failure
 
static fr_dict_attr_t const * attr_freeradius_snmp_operation
 
static fr_dict_attr_t const * attr_freeradius_snmp_type
 
static fr_dict_attr_t const * attr_message_authenticator
 
static fr_dict_attr_t const * attr_vendor_specific
 
static fr_dict_t const * dict_freeradius
 
static fr_dict_t const * dict_radius
 
static fr_table_num_sorted_t const radsnmp_command_str []
 
static size_t radsnmp_command_str_len = NUM_ELEMENTS(radsnmp_command_str)
 
fr_dict_autoload_t radsnmp_dict []
 
fr_dict_attr_autoload_t radsnmp_dict_attr []
 
static char const * radsnmp_version = RADIUSD_VERSION_BUILD("radsnmp")
 
static bool stop
 

Data Structure Documentation

◆ radsnmp_conf_t

struct radsnmp_conf_t

Definition at line 76 of file radsnmp.c.

+ Collaboration diagram for radsnmp_conf_t:
Data Fields
unsigned int code Request type.
fr_dict_t * dict Radius protocol dictionary.
char const * dict_dir Dictionary director.
uint8_t last_used_id ID of the last request we sent.
int proto Protocol TCP/UDP.
char const * proto_str Protocol string.
char const * raddb_dir Radius dictionary directory.
unsigned int retries Number of retries.
char * secret Shared secret.
fr_ipaddr_t server_ipaddr Src IP address.
uint16_t server_port Port to send requests to.
fr_dict_attr_t const * snmp_failure SNMP set error attribute.
fr_dict_attr_t const * snmp_oid_root First attribute to include at the start of OID responses.
fr_dict_attr_t const * snmp_op SNMP operation.
fr_dict_attr_t const * snmp_root SNMP protocol root in the FreeRADIUS dictionary.
fr_dict_attr_t const * snmp_type SNMP type attribute.
fr_time_delta_t timeout

Macro Definition Documentation

◆ DEBUG

#define DEBUG (   fmt,
  ... 
)    if (fr_debug_lvl >= L_DBG_LVL_1) fr_log(&default_log, L_DBG, __FILE__, __LINE__, "radsnmp (debug): " fmt, ## __VA_ARGS__)

Definition at line 52 of file radsnmp.c.

◆ DEBUG2

#define DEBUG2 (   fmt,
  ... 
)    if (fr_debug_lvl >= L_DBG_LVL_2) fr_log(&default_log, L_DBG, __FILE__, __LINE__, "radsnmp (debug): " fmt, ## __VA_ARGS__)

Definition at line 54 of file radsnmp.c.

◆ ERROR

#define ERROR (   fmt,
  ... 
)    fr_log(&default_log, L_DBG, __FILE__, __LINE__, "radsnmp (error): " fmt, ## __VA_ARGS__)

Definition at line 56 of file radsnmp.c.

◆ NEXT_LINE

#define NEXT_LINE (   _line,
  _buffer 
)
Value:
do { \
size_t _len; \
if (stop) return 0; \
errno = 0;\
_line = fgets(_buffer, sizeof(_buffer), stdin); \
if (_line) { \
_len = strlen(_line); \
if ((_len > 0) && (_line[_len - 1] == '\n')) _line[_len - 1] = '\0'; \
DEBUG2("read: %s", _line); \
} \
} while (0)
while(1)
Definition: acutest.h:856
static bool stop
Definition: radsnmp.c:49
#define DEBUG2(fmt,...)
Definition: radsnmp.c:54

◆ RESPOND_STATIC

#define RESPOND_STATIC (   _cmd)
Value:
do {\
DEBUG2("said: %s", _cmd);\
if (write(STDOUT_FILENO, _cmd "\n", sizeof(_cmd)) < 0) return 1; \
} while (0)
return
Definition: module.c:174

Definition at line 148 of file radsnmp.c.

Enumeration Type Documentation

◆ radsnmp_command_t

Enumerator
RADSNMP_UNKNOWN 

Unknown command.

RADSNMP_PING 

Check server is alive.

RADSNMP_GET 

Get an SNMP leaf value.

RADSNMP_GETNEXT 

Get next OID.

RADSNMP_SET 

Set OID.

RADSNMP_EXIT 

Terminate gracefully.

Definition at line 58 of file radsnmp.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 896 of file radsnmp.c.

◆ radsnmp_alloc()

static fr_packet_t* radsnmp_alloc ( radsnmp_conf_t conf,
int  fd 
)
static

Allocate a new request using values from radsnmp config.

Parameters
confradsnmp config.
fdthe request will be sent on.
Returns
new request.

Definition at line 165 of file radsnmp.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ radsnmp_get_response()

static int radsnmp_get_response ( int  fd,
fr_dict_attr_t const *  root,
fr_dict_attr_t const *  type,
fr_pair_list_t head 
)
static

Write the result of a get or getnext operation back to net-snmp.

Returns three lines of output per attribute:

  • OID string
  • type
  • value

Index attributes (num 0) must be in order of depth (shallowest first).

If no attributes were written, will write "NONE\n" to inform net-snmp that no value was available at the specified OID.

Parameters
fdto write to.
rootof the SNMP portion of the main dictionary.
typeattribute.
headof list of attributes to convert and write.
Returns
  • >=0 on success (the number of varbind responses written).
  • -1 on failure.

Definition at line 382 of file radsnmp.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ radsnmp_pair_from_oid()

static ssize_t radsnmp_pair_from_oid ( TALLOC_CTX *  ctx,
radsnmp_conf_t conf,
fr_dcursor_t cursor,
char const *  oid,
int  type,
char const *  value 
)
static

Builds attribute representing OID string and adds 'index' attributes where required.

Will convert an OID string in the format

.1.2.3.4.5.0 

into a pair with a fr_dict_attr_t of the dictionary attribute matching the OID string, as evaluated from the specified parent.

If an OID component does not match a child of a previous OID component, but a child with attribute number 0 exists, and a child with attribute number 1 also exists, the child with attribute number 0 will be used as an 'index' pair, and will be created with the value of the non matching OID component.

Parsing will then resume using the child with attribute number 1.

This allows traversals of SNMP tables to be represented by the sequence of pairs and allows the full range of entry indexes which would not be possible if we represented table index numbers as TLV attributes.

Parameters
[in]ctxto allocate new pairs in.
[in]confradsnmp config.
[in]cursorto add pairs to.
[in]oidstring to evaluate.
[in]typeSNMP value type.
[in]valueto assign to OID attribute (SET operations only).
Returns
  • >0 on success (how much of the OID string we parsed).
  • <=0 on failure (where format error occurred).

Definition at line 210 of file radsnmp.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ radsnmp_send_recv()

static int radsnmp_send_recv ( radsnmp_conf_t conf,
int  fd 
)
static

Definition at line 628 of file radsnmp.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ radsnmp_set_response()

static int radsnmp_set_response ( int  fd,
fr_dict_attr_t const *  error,
fr_pair_list_t head 
)
static

Write the result of a set operation back to net-snmp.

Writes "DONE\n" on success, or an error as described in man snmpd.conf on error.

Parameters
fdto write to.
errorattribute.
headof list of attributes to convert and write.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 590 of file radsnmp.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rs_signal_stop()

static void rs_signal_stop ( UNUSED int  sig)
static

Definition at line 154 of file radsnmp.c.

+ Here is the caller graph for this function:

◆ usage()

static NEVER_RETURNS void usage ( void  )
static

Definition at line 126 of file radsnmp.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ attr_extended_attribute_1

fr_dict_attr_t const* attr_extended_attribute_1
static

Definition at line 108 of file radsnmp.c.

◆ attr_freeradius_snmp_failure

fr_dict_attr_t const* attr_freeradius_snmp_failure
static

Definition at line 109 of file radsnmp.c.

◆ attr_freeradius_snmp_operation

fr_dict_attr_t const* attr_freeradius_snmp_operation
static

Definition at line 110 of file radsnmp.c.

◆ attr_freeradius_snmp_type

fr_dict_attr_t const* attr_freeradius_snmp_type
static

Definition at line 111 of file radsnmp.c.

◆ attr_message_authenticator

fr_dict_attr_t const* attr_message_authenticator
static

Definition at line 112 of file radsnmp.c.

◆ attr_vendor_specific

fr_dict_attr_t const* attr_vendor_specific
static

Definition at line 113 of file radsnmp.c.

◆ dict_freeradius

fr_dict_t const* dict_freeradius
static

Definition at line 98 of file radsnmp.c.

◆ dict_radius

fr_dict_t const* dict_radius
static

Definition at line 99 of file radsnmp.c.

◆ radsnmp_command_str

fr_table_num_sorted_t const radsnmp_command_str[]
static
Initial value:
= {
{ L(""), RADSNMP_EXIT },
{ L("PING"), RADSNMP_PING },
{ L("get"), RADSNMP_GET },
{ L("getnext"), RADSNMP_GETNEXT },
{ L("set"), RADSNMP_SET },
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
@ RADSNMP_PING
Check server is alive.
Definition: radsnmp.c:60
@ RADSNMP_SET
Set OID.
Definition: radsnmp.c:63
@ RADSNMP_GET
Get an SNMP leaf value.
Definition: radsnmp.c:61
@ RADSNMP_EXIT
Terminate gracefully.
Definition: radsnmp.c:64
@ RADSNMP_GETNEXT
Get next OID.
Definition: radsnmp.c:62

Definition at line 67 of file radsnmp.c.

◆ radsnmp_command_str_len

size_t radsnmp_command_str_len = NUM_ELEMENTS(radsnmp_command_str)
static

Definition at line 74 of file radsnmp.c.

◆ radsnmp_dict

fr_dict_autoload_t radsnmp_dict
Initial value:
= {
{ .out = &dict_freeradius, .proto = "freeradius" },
{ .out = &dict_radius, .proto = "radius" },
{ NULL }
}
static fr_dict_t const * dict_freeradius
Definition: radsnmp.c:98
static fr_dict_t const * dict_radius
Definition: radsnmp.c:99

Definition at line 102 of file radsnmp.c.

◆ radsnmp_dict_attr

fr_dict_attr_autoload_t radsnmp_dict_attr
Initial value:
= {
{ .out = &attr_extended_attribute_1, .name = "Extended-Attribute-1", .type = FR_TYPE_TLV, .dict = &dict_radius },
{ .out = &attr_freeradius_snmp_failure, .name = "FreeRADIUS-SNMP-Failure", .type = FR_TYPE_UINT8, .dict = &dict_radius },
{ .out = &attr_freeradius_snmp_operation, .name = "FreeRADIUS-SNMP-Operation", .type = FR_TYPE_UINT8, .dict = &dict_radius },
{ .out = &attr_freeradius_snmp_type, .name = "FreeRADIUS-SNMP-Type", .type = FR_TYPE_UINT8, .dict = &dict_radius },
{ .out = &attr_message_authenticator, .name = "Message-Authenticator", .type = FR_TYPE_OCTETS, .dict = &dict_radius },
{ .out = &attr_vendor_specific, .name = "Vendor-Specific", .type = FR_TYPE_VSA, .dict = &dict_radius },
{ NULL }
}
@ FR_TYPE_TLV
Contains nested attributes.
Definition: merged_model.c:118
@ FR_TYPE_UINT8
8 Bit unsigned integer.
Definition: merged_model.c:97
@ FR_TYPE_VSA
Vendor-Specific, for RADIUS attribute 26.
Definition: merged_model.c:121
@ FR_TYPE_OCTETS
Raw octets.
Definition: merged_model.c:84
static fr_dict_attr_t const * attr_freeradius_snmp_operation
Definition: radsnmp.c:110
static fr_dict_attr_t const * attr_vendor_specific
Definition: radsnmp.c:113
static fr_dict_attr_t const * attr_extended_attribute_1
Definition: radsnmp.c:108
static fr_dict_attr_t const * attr_freeradius_snmp_failure
Definition: radsnmp.c:109
static fr_dict_attr_t const * attr_freeradius_snmp_type
Definition: radsnmp.c:111
static fr_dict_attr_t const * attr_message_authenticator
Definition: radsnmp.c:112

Definition at line 116 of file radsnmp.c.

◆ radsnmp_version

char const* radsnmp_version = RADIUSD_VERSION_BUILD("radsnmp")
static

Definition at line 47 of file radsnmp.c.

◆ stop

bool stop
static

Definition at line 49 of file radsnmp.c.