nl_cb: store nl_cb_type in struct nl_cb
The application could use the same handler for multiple nl_cb_type events. This patch stores the nl_cb_type in the nl_cb struct during the callback. This allows the application to obtain that information using the new nl_cb_active_type() function. This way the callback signature remains as is so existing applications are not affected. Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
This commit is contained in:
parent
9828326c7f
commit
934626903c
4 changed files with 35 additions and 14 deletions
|
@ -128,7 +128,12 @@ extern void dump_from_ops(struct nl_object *, struct nl_dump_params *);
|
|||
|
||||
static inline int nl_cb_call(struct nl_cb *cb, int type, struct nl_msg *msg)
|
||||
{
|
||||
return cb->cb_set[type](msg, cb->cb_args[type]);
|
||||
int ret;
|
||||
|
||||
cb->cb_active = type;
|
||||
ret = cb->cb_set[type](msg, cb->cb_args[type]);
|
||||
cb->cb_active = __NL_CB_TYPE_MAX;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0]))
|
||||
|
|
|
@ -39,7 +39,7 @@ struct nl_cb
|
|||
{
|
||||
nl_recvmsg_msg_cb_t cb_set[NL_CB_TYPE_MAX+1];
|
||||
void * cb_args[NL_CB_TYPE_MAX+1];
|
||||
|
||||
|
||||
nl_recvmsg_err_cb_t cb_err;
|
||||
void * cb_err_arg;
|
||||
|
||||
|
@ -61,6 +61,8 @@ struct nl_cb
|
|||
struct nl_msg *);
|
||||
|
||||
int cb_refcnt;
|
||||
/** indicates the callback that is currently active */
|
||||
enum nl_cb_type cb_active;
|
||||
};
|
||||
|
||||
struct nl_sock
|
||||
|
@ -166,7 +168,7 @@ struct rtnl_link
|
|||
uint32_t l_txqlen;
|
||||
uint32_t l_weight;
|
||||
uint32_t l_master;
|
||||
struct nl_addr * l_addr;
|
||||
struct nl_addr * l_addr;
|
||||
struct nl_addr * l_bcast;
|
||||
char l_qdisc[IFQDISCSIZ];
|
||||
struct rtnl_link_map l_map;
|
||||
|
@ -207,9 +209,9 @@ struct rtnl_neigh
|
|||
uint32_t n_ifindex;
|
||||
uint16_t n_state;
|
||||
uint8_t n_flags;
|
||||
uint8_t n_type;
|
||||
uint8_t n_type;
|
||||
struct nl_addr *n_lladdr;
|
||||
struct nl_addr *n_dst;
|
||||
struct nl_addr *n_dst;
|
||||
uint32_t n_probes;
|
||||
struct rtnl_ncacheinfo n_cacheinfo;
|
||||
uint32_t n_state_mask;
|
||||
|
@ -243,14 +245,14 @@ struct rtnl_addr
|
|||
uint8_t a_scope;
|
||||
uint32_t a_ifindex;
|
||||
|
||||
struct nl_addr *a_peer;
|
||||
struct nl_addr *a_peer;
|
||||
struct nl_addr *a_local;
|
||||
struct nl_addr *a_bcast;
|
||||
struct nl_addr *a_anycast;
|
||||
struct nl_addr *a_multicast;
|
||||
|
||||
struct rtnl_addr_cacheinfo a_cacheinfo;
|
||||
|
||||
|
||||
char a_label[IFNAMSIZ];
|
||||
uint32_t a_flag_mask;
|
||||
struct rtnl_link *a_link;
|
||||
|
@ -402,7 +404,7 @@ struct rtnl_neightbl_parms
|
|||
* Queue length for the delayed proxy arp requests.
|
||||
*/
|
||||
uint32_t ntp_proxy_qlen;
|
||||
|
||||
|
||||
/**
|
||||
* Mask of available parameter attributes
|
||||
*/
|
||||
|
|
|
@ -139,6 +139,8 @@ extern void nl_cb_overwrite_send(struct nl_cb *,
|
|||
int (*func)(struct nl_sock *,
|
||||
struct nl_msg *));
|
||||
|
||||
extern enum nl_cb_type nl_cb_active_type(struct nl_cb *cb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -35,7 +35,7 @@ static void print_header_content(FILE *ofd, struct nlmsghdr *n)
|
|||
{
|
||||
char flags[128];
|
||||
char type[32];
|
||||
|
||||
|
||||
fprintf(ofd, "type=%s length=%u flags=<%s> sequence-nr=%u pid=%u",
|
||||
nl_nlmsgtype2str(n->nlmsg_type, type, sizeof(type)),
|
||||
n->nlmsg_len, nl_nlmsg_flags2str(n->nlmsg_flags, flags,
|
||||
|
@ -71,7 +71,7 @@ static int nl_overrun_handler_verbose(struct nl_msg *msg, void *arg)
|
|||
fprintf(ofd, "-- Error: Netlink Overrun: ");
|
||||
print_header_content(ofd, nlmsg_hdr(msg));
|
||||
fprintf(ofd, "\n");
|
||||
|
||||
|
||||
return NL_STOP;
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ static int nl_finish_handler_debug(struct nl_msg *msg, void *arg)
|
|||
fprintf(ofd, "-- Debug: End of multipart message block: ");
|
||||
print_header_content(ofd, nlmsg_hdr(msg));
|
||||
fprintf(ofd, "\n");
|
||||
|
||||
|
||||
return NL_STOP;
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ static int nl_msg_in_handler_debug(struct nl_msg *msg, void *arg)
|
|||
|
||||
fprintf(ofd, "-- Debug: Received Message:\n");
|
||||
nl_msg_dump(msg, ofd);
|
||||
|
||||
|
||||
return NL_OK;
|
||||
}
|
||||
|
||||
|
@ -211,6 +211,7 @@ struct nl_cb *nl_cb_alloc(enum nl_cb_kind kind)
|
|||
return NULL;
|
||||
|
||||
cb->cb_refcnt = 1;
|
||||
cb->cb_active = NL_CB_TYPE_MAX + 1;
|
||||
|
||||
for (i = 0; i <= NL_CB_TYPE_MAX; i++)
|
||||
nl_cb_set(cb, i, kind, NULL, NULL);
|
||||
|
@ -229,7 +230,7 @@ struct nl_cb *nl_cb_alloc(enum nl_cb_kind kind)
|
|||
struct nl_cb *nl_cb_clone(struct nl_cb *orig)
|
||||
{
|
||||
struct nl_cb *cb;
|
||||
|
||||
|
||||
cb = nl_cb_alloc(NL_CB_DEFAULT);
|
||||
if (!cb)
|
||||
return NULL;
|
||||
|
@ -261,6 +262,17 @@ void nl_cb_put(struct nl_cb *cb)
|
|||
free(cb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain type of current active callback
|
||||
* @arg cb callback to query
|
||||
*
|
||||
* @return type or __NL_CB_TYPE_MAX if none active
|
||||
*/
|
||||
enum nl_cb_type nl_cb_active_type(struct nl_cb *cb)
|
||||
{
|
||||
return cb->cb_active;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
|
@ -269,7 +281,7 @@ void nl_cb_put(struct nl_cb *cb)
|
|||
*/
|
||||
|
||||
/**
|
||||
* Set up a callback
|
||||
* Set up a callback
|
||||
* @arg cb callback set
|
||||
* @arg type callback to modify
|
||||
* @arg kind kind of implementation
|
||||
|
|
Loading…
Add table
Reference in a new issue