can-eth-gw-utils Utilities  0.1
A bidirectional CAN to Ethernet Gateway (Utilities)
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
netlink.c File Reference

Control Area Network - Ethernet - Gateway - Netlink (Utility) More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdint.h>
#include <netlink/netlink.h>
#include <netlink/cache.h>
#include <netlink/attr.h>
#include <netlink/addr.h>
#include <netlink/msg.h>
#include <netlink/errno.h>
#include <netlink/genl/ctrl.h>
#include <netlink/genl/family.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/mngt.h>
#include "netlink.h"
Include dependency graph for netlink.c:

Go to the source code of this file.

Data Structures

struct  flags
 Flags defined in netlink.h. Can used by flags2str(). More...
 
struct  enums
 Array of type "enum gw_type" in netlink.h. Can use by enum2str(). More...
 

Macros

#define GE_FAMILY_NAME   "CE_GW"
 
#define GE_FAMILY_VERSION   1
 
#define USER_HDR_SIZE   0
 
#define NO_FLAG   0
 
#define IFACE_VERSION   0
 
#define CE_GW_A_MAX   (__CE_GW_A_MAX - 1)
 

Enumerations

enum  {
  CE_GW_A_UNSPEC, CE_GW_A_DATA, CE_GW_A_SRC, CE_GW_A_DST,
  CE_GW_A_ID, CE_GW_A_FLAGS, CE_GW_A_TYPE, CE_GW_A_HNDL,
  CE_GW_A_DROP, __CE_GW_A_MAX
}
 

Functions

char * flags2str (uint32_t bits, const struct flags *flags, size_t size)
 Convert Flags in ist textual represenation. More...
 
char * enum2str (int value, const struct enums *enums, size_t size, int max)
 Returns the textual representation of an numeric identifier (enum) More...
 
int nl_cb_general_errno (struct sockaddr_nl *nla, struct nlmsgerr *nlerr, void *arg)
 A callback wich prints the errno to stderr. More...
 
int nl_cb_list_entry (struct nl_msg *msg, void *arg)
 will be called for every multipart message and prints informations to stdout. More...
 
int nl_cb_list_finish (struct nl_msg *msg, void *arg)
 will be called at the end of a multipart message. More...
 
int nl_cb_echo_answer (struct nl_msg *msg, void *arg)
 Callback witch receive the message sen bach by kernel. More...
 
int ce_gw_add (char *dst_name, char *src_name, uint8_t type, uint32_t flags)
 add a virtual ethernet device or a route More...
 
int ce_gw_del (uint32_t id, char *dev_name)
 Deletes a device or a route in Kernel Module. More...
 
int ce_gw_list (uint32_t id)
 Print informations of actual active routes to stdout. More...
 
int ce_gw_echo (char *message)
 send a message and return the received message from Kernel. (for testing) More...
 
int nl_sk_fam_init (void)
 creakte socket and family and connect More...
 
void nl_sk_fam_exit (void)
 freeing the alloccated memory. The Function free the memory allocated by nl_sk_fam_init(). More...
 

Variables

static struct nla_policy ce_gw_genl_policy [CE_GW_A_MAX+1]
 Netlink Policy - Defines the Type for the Netlink Attributes. More...
 
struct genl_family * genl_fam
 
struct nl_sock * nl_sk
 
struct flags flags_array []
 
struct enums type_array []
 

Detailed Description

Control Area Network - Ethernet - Gateway - Netlink (Utility)

Author
Fabian Raab (fabia.nosp@m.n.ra.nosp@m.ab@tu.nosp@m.m.de)
Date
May, 2013

Definition in file netlink.c.

Macro Definition Documentation

#define CE_GW_A_MAX   (__CE_GW_A_MAX - 1)

Maximum Number of Attribute

Definition at line 73 of file netlink.c.

Referenced by ce_gw_add(), ce_gw_del(), ce_gw_echo(), ce_gw_list(), nl_cb_list_entry(), and nl_sk_fam_init().

#define GE_FAMILY_NAME   "CE_GW"

Netlink Family Settings

Definition at line 50 of file netlink.c.

Referenced by nl_sk_fam_init().

#define GE_FAMILY_VERSION   1

Definition at line 51 of file netlink.c.

Referenced by nl_sk_fam_init().

#define IFACE_VERSION   0

Definition at line 54 of file netlink.c.

Referenced by ce_gw_add(), ce_gw_del(), ce_gw_echo(), and ce_gw_list().

#define NO_FLAG   0

Definition at line 53 of file netlink.c.

Referenced by ce_gw_add(), ce_gw_del(), ce_gw_echo(), and ce_gw_list().

#define USER_HDR_SIZE   0

user header size

Definition at line 52 of file netlink.c.

Referenced by ce_gw_add(), ce_gw_del(), ce_gw_echo(), ce_gw_list(), nl_cb_list_entry(), and nl_sk_fam_init().

Enumeration Type Documentation

anonymous enum
Enumerator
CE_GW_A_UNSPEC 

Only a Dummy to skip index 0.

CE_GW_A_DATA 

NLA_STRING

CE_GW_A_SRC 

NLA_STRING

CE_GW_A_DST 

NLA_STRING

CE_GW_A_ID 

NLA_U32

CE_GW_A_FLAGS 

NLA_U32

CE_GW_A_TYPE 

NLA_U8

CE_GW_A_HNDL 

NLA_U32 Handled Frames

CE_GW_A_DROP 

NLA_U32 Dropped Frames

__CE_GW_A_MAX 

Maximum Number of Attribute plus 1

Definition at line 61 of file netlink.c.

61  {
63  CE_GW_A_DATA,
64  CE_GW_A_SRC,
65  CE_GW_A_DST,
66  CE_GW_A_ID,
68  CE_GW_A_TYPE,
69  CE_GW_A_HNDL,
70  CE_GW_A_DROP,
72 };

Variable Documentation

struct nla_policy ce_gw_genl_policy[CE_GW_A_MAX+1]
static
Initial value:
= {
[CE_GW_A_DATA] = { .type = NLA_STRING },
[CE_GW_A_SRC] = { .type = NLA_STRING },
[CE_GW_A_DST] = { .type = NLA_STRING },
[CE_GW_A_ID] = { .type = NLA_U32 },
[CE_GW_A_FLAGS] = { .type = NLA_U32 },
[CE_GW_A_TYPE] = { .type = NLA_U8 },
[CE_GW_A_HNDL] = { .type = NLA_U32 },
[CE_GW_A_DROP] = { .type = NLA_U32 },
}

Netlink Policy - Defines the Type for the Netlink Attributes.

Definition at line 78 of file netlink.c.

Referenced by ce_gw_add(), ce_gw_del(), ce_gw_echo(), ce_gw_list(), and nl_cb_list_entry().

struct flags flags_array[]
Initial value:
= {
{ "CAN-FD" },
{ 0 }
}

Referenced by nl_cb_list_entry().

struct genl_family* genl_fam

Generic Netlink Family

Definition at line 89 of file netlink.c.

Referenced by ce_gw_add(), ce_gw_del(), ce_gw_echo(), ce_gw_list(), nl_sk_fam_exit(), and nl_sk_fam_init().

struct nl_sock* nl_sk

Socket to Kernel Application

Definition at line 90 of file netlink.c.

Referenced by ce_gw_add(), ce_gw_del(), ce_gw_echo(), ce_gw_list(), nl_sk_fam_exit(), and nl_sk_fam_init().

struct enums type_array[]
Initial value:
= {
{ "NONE" },
{ "ETH" },
{ "NET" },
{ "TCP" },
{ "UDP" },
{ 0 }
}

Referenced by nl_cb_list_entry().