All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
radsnmp.c File Reference
#include <freeradius-devel/conf.h>
#include <freeradius-devel/libradius.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
 

Macros

#define DEBUG(fmt,...)   if (fr_debug_lvl > 0) fprintf(fr_log_fp, "radsnmp (debug): " fmt "\n", ## __VA_ARGS__)
 
#define DEBUG2(fmt,...)   if (fr_debug_lvl > 1) fprintf(fr_log_fp, "radsnmp (debug): " fmt "\n", ## __VA_ARGS__)
 
#define ERROR(fmt,...)   fprintf(fr_log_fp, "radsnmp (error): " fmt "\n", ## __VA_ARGS__)
 
#define NEXT_LINE(_line, _buffer)
 
#define RESPOND_STATIC(_cmd)
 

Typedefs

typedef struct radsnmp_conf radsnmp_conf_t
 

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 RADIUS_PACKETradsnmp_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, VALUE_PAIR *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, vp_cursor_t *cursor, fr_dict_t *dict, fr_dict_attr_t const *parent, char const *oid, 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, VALUE_PAIR *head)
 Write the result of a set operation back to net-snmp. More...
 
static void rs_signal_stop (UNUSED int sig)
 
static void NEVER_RETURNS usage (void)
 

Variables

static const FR_NAME_NUMBER radsnmp_command_str []
 
static char const * radsnmp_version
 
static bool stop
 

Data Structure Documentation

struct radsnmp_conf

Definition at line 75 of file radsnmp.c.

+ Collaboration diagram for radsnmp_conf:
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 * radius_dir Radius dictionary directory.
unsigned int retries Number of retries.
char const * 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.
struct timeval timeout

Macro Definition Documentation

#define DEBUG (   fmt,
  ... 
)    if (fr_debug_lvl > 0) fprintf(fr_log_fp, "radsnmp (debug): " fmt "\n", ## __VA_ARGS__)

Definition at line 51 of file radsnmp.c.

#define DEBUG2 (   fmt,
  ... 
)    if (fr_debug_lvl > 1) fprintf(fr_log_fp, "radsnmp (debug): " fmt "\n", ## __VA_ARGS__)

Definition at line 53 of file radsnmp.c.

#define ERROR (   fmt,
  ... 
)    fprintf(fr_log_fp, "radsnmp (error): " fmt "\n", ## __VA_ARGS__)

Definition at line 55 of file radsnmp.c.

#define NEXT_LINE (   _line,
  _buffer 
)
Value:
{ \
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); \
} \
}
static bool stop
Definition: radsnmp.c:48
#define DEBUG2(fmt,...)
Definition: radsnmp.c:53
#define RESPOND_STATIC (   _cmd)
Value:
do {\
DEBUG2("said: %s", _cmd);\
if (write(STDOUT_FILENO, _cmd "\n", sizeof(_cmd)) < 0) return 1; \
} while (0)
#define DEBUG2(fmt,...)
Definition: radsnmp.c:53

Definition at line 122 of file radsnmp.c.

Typedef Documentation

typedef struct radsnmp_conf radsnmp_conf_t

Enumeration Type Documentation

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 57 of file radsnmp.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 817 of file radsnmp.c.

+ Here is the call graph for this function:

static RADIUS_PACKET* 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 139 of file radsnmp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int radsnmp_get_response ( int  fd,
fr_dict_attr_t const *  root,
fr_dict_attr_t const *  type,
VALUE_PAIR 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 343 of file radsnmp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t radsnmp_pair_from_oid ( TALLOC_CTX *  ctx,
vp_cursor_t cursor,
fr_dict_t dict,
fr_dict_attr_t const *  parent,
char const *  oid,
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
ctxto allocate new pairs in.
cursorto add pairs to.
dictfor RADIUS protocol.
parentWhere to start evaluating OID strings from.
oidstring to evaluate.
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 184 of file radsnmp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int radsnmp_send_recv ( radsnmp_conf_t conf,
int  fd 
)
static

Definition at line 563 of file radsnmp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int radsnmp_set_response ( int  fd,
fr_dict_attr_t const *  error,
VALUE_PAIR 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 525 of file radsnmp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rs_signal_stop ( UNUSED int  sig)
static

Definition at line 128 of file radsnmp.c.

+ Here is the caller graph for this function:

static void NEVER_RETURNS usage ( void  )
static

Definition at line 97 of file radsnmp.c.

+ Here is the caller graph for this function:

Variable Documentation

const FR_NAME_NUMBER radsnmp_command_str[]
static
Initial value:
= {
{ "PING", RADSNMP_PING },
{ "get", RADSNMP_GET },
{ "getnext", RADSNMP_GETNEXT },
{ "set", RADSNMP_SET },
{ "", RADSNMP_EXIT },
{ NULL , -1}
}
Set OID.
Definition: radsnmp.c:62
Get next OID.
Definition: radsnmp.c:61
Terminate gracefully.
Definition: radsnmp.c:63
Check server is alive.
Definition: radsnmp.c:59
Get an SNMP leaf value.
Definition: radsnmp.c:60

Definition at line 66 of file radsnmp.c.

char const* radsnmp_version
static
Initial value:
= "radsnmp version " RADIUSD_VERSION_STRING
", built on " __DATE__ " at " __TIME__

Definition at line 42 of file radsnmp.c.

bool stop
static

Definition at line 48 of file radsnmp.c.