Commit 328d482c authored by Julian Anastasov's avatar Julian Anastasov Committed by Stephen Hemminger

iproute2: GENL: merge GENL_REQUEST and GENL_INITIALIZER

	Both macros are used together, so better to have
single define. Update all requests in ipl2tp.c to use the
new macro.
Signed-off-by: default avatarJulian Anastasov <ja@ssi.bg>
parent bd899db3
...@@ -3,25 +3,22 @@ ...@@ -3,25 +3,22 @@
#include "libnetlink.h" #include "libnetlink.h"
#define GENL_REQUEST(_req, _hdrsiz, _bufsiz) \ #define GENL_REQUEST(_req, _bufsiz, _family, _hdrsiz, _ver, _cmd, _flags) \
struct { \ struct { \
struct nlmsghdr n; \ struct nlmsghdr n; \
struct genlmsghdr g; \ struct genlmsghdr g; \
char buf[NLMSG_ALIGN(_hdrsiz) + (_bufsiz)]; \ char buf[NLMSG_ALIGN(_hdrsiz) + (_bufsiz)]; \
} _req } _req = { \
.n = { \
#define GENL_INITIALIZER(_family, _hdrsiz, _ver, _cmd, _flags) \ .nlmsg_type = (_family), \
{ \ .nlmsg_flags = (_flags), \
.n = { \ .nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN + (_hdrsiz)), \
.nlmsg_type = (_family), \ }, \
.nlmsg_flags = (_flags), \ .g = { \
.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN + (_hdrsiz)), \ .cmd = (_cmd), \
}, \ .version = (_ver), \
.g = { \ }, \
.cmd = (_cmd), \ }
.version = (_ver), \
}, \
}
extern int genl_resolve_family(struct rtnl_handle *grth, const char *family); extern int genl_resolve_family(struct rtnl_handle *grth, const char *family);
......
...@@ -96,9 +96,8 @@ static int create_tunnel(struct l2tp_parm *p) ...@@ -96,9 +96,8 @@ static int create_tunnel(struct l2tp_parm *p)
uint32_t local_attr = L2TP_ATTR_IP_SADDR; uint32_t local_attr = L2TP_ATTR_IP_SADDR;
uint32_t peer_attr = L2TP_ATTR_IP_DADDR; uint32_t peer_attr = L2TP_ATTR_IP_DADDR;
GENL_REQUEST(req, 0, 1024) GENL_REQUEST(req, 1024, genl_family, 0, L2TP_GENL_VERSION,
= GENL_INITIALIZER(genl_family, NLM_F_REQUEST | NLM_F_ACK, 0, L2TP_CMD_TUNNEL_CREATE, NLM_F_REQUEST | NLM_F_ACK);
L2TP_CMD_TUNNEL_CREATE, L2TP_GENL_VERSION);
addattr32(&req.n, 1024, L2TP_ATTR_CONN_ID, p->tunnel_id); addattr32(&req.n, 1024, L2TP_ATTR_CONN_ID, p->tunnel_id);
addattr32(&req.n, 1024, L2TP_ATTR_PEER_CONN_ID, p->peer_tunnel_id); addattr32(&req.n, 1024, L2TP_ATTR_PEER_CONN_ID, p->peer_tunnel_id);
...@@ -126,9 +125,8 @@ static int create_tunnel(struct l2tp_parm *p) ...@@ -126,9 +125,8 @@ static int create_tunnel(struct l2tp_parm *p)
static int delete_tunnel(struct l2tp_parm *p) static int delete_tunnel(struct l2tp_parm *p)
{ {
GENL_REQUEST(req, 0, 1024) GENL_REQUEST(req, 128, genl_family, 0, L2TP_GENL_VERSION,
= GENL_INITIALIZER(genl_family, NLM_F_REQUEST | NLM_F_ACK, 0, L2TP_CMD_TUNNEL_DELETE, NLM_F_REQUEST | NLM_F_ACK);
L2TP_CMD_TUNNEL_DELETE, L2TP_GENL_VERSION);
addattr32(&req.n, 128, L2TP_ATTR_CONN_ID, p->tunnel_id); addattr32(&req.n, 128, L2TP_ATTR_CONN_ID, p->tunnel_id);
...@@ -140,18 +138,8 @@ static int delete_tunnel(struct l2tp_parm *p) ...@@ -140,18 +138,8 @@ static int delete_tunnel(struct l2tp_parm *p)
static int create_session(struct l2tp_parm *p) static int create_session(struct l2tp_parm *p)
{ {
struct { GENL_REQUEST(req, 1024, genl_family, 0, L2TP_GENL_VERSION,
struct nlmsghdr n; L2TP_CMD_SESSION_CREATE, NLM_F_REQUEST | NLM_F_ACK);
struct genlmsghdr g;
char buf[1024];
} req;
memset(&req, 0, sizeof(req));
req.n.nlmsg_type = genl_family;
req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
req.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
req.g.cmd = L2TP_CMD_SESSION_CREATE;
req.g.version = L2TP_GENL_VERSION;
addattr32(&req.n, 1024, L2TP_ATTR_CONN_ID, p->tunnel_id); addattr32(&req.n, 1024, L2TP_ATTR_CONN_ID, p->tunnel_id);
addattr32(&req.n, 1024, L2TP_ATTR_PEER_CONN_ID, p->peer_tunnel_id); addattr32(&req.n, 1024, L2TP_ATTR_PEER_CONN_ID, p->peer_tunnel_id);
...@@ -182,18 +170,8 @@ static int create_session(struct l2tp_parm *p) ...@@ -182,18 +170,8 @@ static int create_session(struct l2tp_parm *p)
static int delete_session(struct l2tp_parm *p) static int delete_session(struct l2tp_parm *p)
{ {
struct { GENL_REQUEST(req, 1024, genl_family, 0, L2TP_GENL_VERSION,
struct nlmsghdr n; L2TP_CMD_SESSION_DELETE, NLM_F_REQUEST | NLM_F_ACK);
struct genlmsghdr g;
char buf[128];
} req;
memset(&req, 0, sizeof(req));
req.n.nlmsg_type = genl_family;
req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
req.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
req.g.cmd = L2TP_CMD_SESSION_DELETE;
req.g.version = L2TP_GENL_VERSION;
addattr32(&req.n, 1024, L2TP_ATTR_CONN_ID, p->tunnel_id); addattr32(&req.n, 1024, L2TP_ATTR_CONN_ID, p->tunnel_id);
addattr32(&req.n, 1024, L2TP_ATTR_SESSION_ID, p->session_id); addattr32(&req.n, 1024, L2TP_ATTR_SESSION_ID, p->session_id);
...@@ -380,20 +358,11 @@ static int session_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void ...@@ -380,20 +358,11 @@ static int session_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void
static int get_session(struct l2tp_data *p) static int get_session(struct l2tp_data *p)
{ {
struct { GENL_REQUEST(req, 128, genl_family, 0, L2TP_GENL_VERSION,
struct nlmsghdr n; L2TP_CMD_SESSION_GET,
struct genlmsghdr g; NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST);
char buf[128];
} req;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
req.n.nlmsg_type = genl_family;
req.n.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
req.n.nlmsg_seq = genl_rth.dump = ++genl_rth.seq;
req.g.cmd = L2TP_CMD_SESSION_GET; req.n.nlmsg_seq = genl_rth.dump = ++genl_rth.seq;
req.g.version = L2TP_GENL_VERSION;
if (p->config.tunnel_id && p->config.session_id) { if (p->config.tunnel_id && p->config.session_id) {
addattr32(&req.n, 128, L2TP_ATTR_CONN_ID, p->config.tunnel_id); addattr32(&req.n, 128, L2TP_ATTR_CONN_ID, p->config.tunnel_id);
...@@ -423,20 +392,11 @@ static int tunnel_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void ...@@ -423,20 +392,11 @@ static int tunnel_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void
static int get_tunnel(struct l2tp_data *p) static int get_tunnel(struct l2tp_data *p)
{ {
struct { GENL_REQUEST(req, 1024, genl_family, 0, L2TP_GENL_VERSION,
struct nlmsghdr n; L2TP_CMD_TUNNEL_GET,
struct genlmsghdr g; NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST);
char buf[1024];
} req;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
req.n.nlmsg_type = genl_family;
req.n.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
req.n.nlmsg_seq = genl_rth.dump = ++genl_rth.seq;
req.g.cmd = L2TP_CMD_TUNNEL_GET; req.n.nlmsg_seq = genl_rth.dump = ++genl_rth.seq;
req.g.version = L2TP_GENL_VERSION;
if (p->config.tunnel_id) if (p->config.tunnel_id)
addattr32(&req.n, 1024, L2TP_ATTR_CONN_ID, p->config.tunnel_id); addattr32(&req.n, 1024, L2TP_ATTR_CONN_ID, p->config.tunnel_id);
......
...@@ -47,11 +47,10 @@ static int genl_parse_getfamily(struct nlmsghdr *nlh) ...@@ -47,11 +47,10 @@ static int genl_parse_getfamily(struct nlmsghdr *nlh)
int genl_resolve_family(struct rtnl_handle *grth, const char *family) int genl_resolve_family(struct rtnl_handle *grth, const char *family)
{ {
GENL_REQUEST(req, 0, 1024) GENL_REQUEST(req, 1024, GENL_ID_CTRL, 0, 0, CTRL_CMD_GETFAMILY,
= GENL_INITIALIZER(GENL_ID_CTRL, 0, NLM_F_REQUEST);
0, CTRL_CMD_GETFAMILY, NLM_F_REQUEST);
addattr_l(&req.n, 1024, CTRL_ATTR_FAMILY_NAME, addattr_l(&req.n, sizeof(req), CTRL_ATTR_FAMILY_NAME,
family, strlen(family) + 1); family, strlen(family) + 1);
if (rtnl_talk(grth, &req.n, 0, 0, &req.n) < 0) { if (rtnl_talk(grth, &req.n, 0, 0, &req.n) < 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment