Rename struct nl_handle to struct nl_sock
The idea of a common handle is long revised and only misleading, nl_handle really represents a socket with some additional action handlers assigned to it. Alias for nl_handle is kept for backwards compatibility.
This commit is contained in:
parent
0cf780859c
commit
1155370f52
50 changed files with 528 additions and 538 deletions
|
@ -26,7 +26,7 @@
|
|||
#define NL_MSG_CRED_PRESENT 1
|
||||
|
||||
struct nl_cache_ops;
|
||||
struct nl_handle;
|
||||
struct nl_sock;
|
||||
struct nl_object;
|
||||
|
||||
struct nl_cb
|
||||
|
@ -39,34 +39,34 @@ struct nl_cb
|
|||
|
||||
/** May be used to replace nl_recvmsgs with your own implementation
|
||||
* in all internal calls to nl_recvmsgs. */
|
||||
int (*cb_recvmsgs_ow)(struct nl_handle *,
|
||||
int (*cb_recvmsgs_ow)(struct nl_sock *,
|
||||
struct nl_cb *);
|
||||
|
||||
/** Overwrite internal calls to nl_recv, must return the number of
|
||||
* octets read and allocate a buffer for the received data. */
|
||||
int (*cb_recv_ow)(struct nl_handle *,
|
||||
int (*cb_recv_ow)(struct nl_sock *,
|
||||
struct sockaddr_nl *,
|
||||
unsigned char **,
|
||||
struct ucred **);
|
||||
|
||||
/** Overwrites internal calls to nl_send, must send the netlink
|
||||
* message. */
|
||||
int (*cb_send_ow)(struct nl_handle *,
|
||||
int (*cb_send_ow)(struct nl_sock *,
|
||||
struct nl_msg *);
|
||||
|
||||
int cb_refcnt;
|
||||
};
|
||||
|
||||
struct nl_handle
|
||||
struct nl_sock
|
||||
{
|
||||
struct sockaddr_nl h_local;
|
||||
struct sockaddr_nl h_peer;
|
||||
int h_fd;
|
||||
int h_proto;
|
||||
unsigned int h_seq_next;
|
||||
unsigned int h_seq_expect;
|
||||
int h_flags;
|
||||
struct nl_cb * h_cb;
|
||||
struct sockaddr_nl s_local;
|
||||
struct sockaddr_nl s_peer;
|
||||
int s_fd;
|
||||
int s_proto;
|
||||
unsigned int s_seq_next;
|
||||
unsigned int s_seq_expect;
|
||||
int s_flags;
|
||||
struct nl_cb * s_cb;
|
||||
};
|
||||
|
||||
struct nl_cache
|
||||
|
@ -89,7 +89,7 @@ struct nl_cache_mngr
|
|||
int cm_protocol;
|
||||
int cm_flags;
|
||||
int cm_nassocs;
|
||||
struct nl_handle * cm_handle;
|
||||
struct nl_sock * cm_handle;
|
||||
struct nl_cache_assoc * cm_assocs;
|
||||
};
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ extern "C" {
|
|||
* // function which must trigger a complete dump on the kernel-side of
|
||||
* // whatever the cache covers.
|
||||
* static int my_request_update(struct nl_cache *cache,
|
||||
* struct nl_handle *socket)
|
||||
* struct nl_sock *socket)
|
||||
* {
|
||||
* // In this example, we request a full dump of the interface table
|
||||
* return nl_rtgen_request(socket, RTM_GETLINK, AF_UNSPEC, NLM_F_DUMP);
|
||||
|
@ -172,7 +172,7 @@ struct nl_cache_ops
|
|||
* Called whenever an update of the cache is required. Must send
|
||||
* a request message to the kernel requesting a complete dump.
|
||||
*/
|
||||
int (*co_request_update)(struct nl_cache *, struct nl_handle *);
|
||||
int (*co_request_update)(struct nl_cache *, struct nl_sock *);
|
||||
|
||||
/**
|
||||
* Called whenever a message was received that needs to be parsed.
|
||||
|
|
|
@ -38,7 +38,7 @@ extern struct nl_object * nl_cache_get_prev(struct nl_object *);
|
|||
|
||||
extern struct nl_cache * nl_cache_alloc(struct nl_cache_ops *);
|
||||
extern int nl_cache_alloc_and_fill(struct nl_cache_ops *,
|
||||
struct nl_handle *,
|
||||
struct nl_sock *,
|
||||
struct nl_cache **);
|
||||
extern int nl_cache_alloc_name(const char *,
|
||||
struct nl_cache **);
|
||||
|
@ -53,11 +53,11 @@ extern int nl_cache_add(struct nl_cache *,
|
|||
extern int nl_cache_parse_and_add(struct nl_cache *,
|
||||
struct nl_msg *);
|
||||
extern void nl_cache_remove(struct nl_object *);
|
||||
extern int nl_cache_refill(struct nl_handle *,
|
||||
extern int nl_cache_refill(struct nl_sock *,
|
||||
struct nl_cache *);
|
||||
extern int nl_cache_pickup(struct nl_handle *,
|
||||
extern int nl_cache_pickup(struct nl_sock *,
|
||||
struct nl_cache *);
|
||||
extern int nl_cache_resync(struct nl_handle *,
|
||||
extern int nl_cache_resync(struct nl_sock *,
|
||||
struct nl_cache *,
|
||||
change_func_t);
|
||||
extern int nl_cache_include(struct nl_cache *,
|
||||
|
@ -106,7 +106,7 @@ struct nl_cache_mngr;
|
|||
|
||||
#define NL_AUTO_PROVIDE 1
|
||||
|
||||
extern int nl_cache_mngr_alloc(struct nl_handle *,
|
||||
extern int nl_cache_mngr_alloc(struct nl_sock *,
|
||||
int, int,
|
||||
struct nl_cache_mngr **);
|
||||
extern int nl_cache_mngr_add(struct nl_cache_mngr *,
|
||||
|
|
|
@ -31,7 +31,7 @@ extern struct nl_cache * flnl_result_alloc_cache(void);
|
|||
extern int flnl_lookup_build_request(struct flnl_request *,
|
||||
int,
|
||||
struct nl_msg **);
|
||||
extern int flnl_lookup(struct nl_handle *,
|
||||
extern int flnl_lookup(struct nl_sock *,
|
||||
struct flnl_request *,
|
||||
struct nl_cache *);
|
||||
|
||||
|
|
|
@ -22,12 +22,12 @@ extern "C" {
|
|||
|
||||
struct genl_family;
|
||||
|
||||
extern int genl_ctrl_alloc_cache(struct nl_handle *,
|
||||
extern int genl_ctrl_alloc_cache(struct nl_sock *,
|
||||
struct nl_cache **);
|
||||
extern struct genl_family * genl_ctrl_search(struct nl_cache *, int);
|
||||
extern struct genl_family * genl_ctrl_search_by_name(struct nl_cache *,
|
||||
const char *);
|
||||
extern int genl_ctrl_resolve(struct nl_handle *,
|
||||
extern int genl_ctrl_resolve(struct nl_sock *,
|
||||
const char *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
|
||||
* Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
|
||||
*/
|
||||
|
||||
#ifndef NETLINK_GENL_H_
|
||||
|
@ -20,9 +20,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int genl_connect(struct nl_handle *);
|
||||
extern int genl_connect(struct nl_sock *);
|
||||
|
||||
extern int genl_send_simple(struct nl_handle *, int, int,
|
||||
extern int genl_send_simple(struct nl_sock *, int, int,
|
||||
int, int);
|
||||
|
||||
extern void * genlmsg_put(struct nl_msg *, uint32_t, uint32_t,
|
||||
|
|
|
@ -23,7 +23,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
struct nl_cb;
|
||||
struct nl_handle;
|
||||
struct nl_sock;
|
||||
struct nl_msg;
|
||||
|
||||
/**
|
||||
|
@ -143,15 +143,15 @@ extern int nl_cb_err(struct nl_cb *, enum nl_cb_kind, nl_recvmsg_err_cb_t,
|
|||
void *);
|
||||
|
||||
extern void nl_cb_overwrite_recvmsgs(struct nl_cb *,
|
||||
int (*func)(struct nl_handle *,
|
||||
int (*func)(struct nl_sock *,
|
||||
struct nl_cb *));
|
||||
extern void nl_cb_overwrite_recv(struct nl_cb *,
|
||||
int (*func)(struct nl_handle *,
|
||||
int (*func)(struct nl_sock *,
|
||||
struct sockaddr_nl *,
|
||||
unsigned char **,
|
||||
struct ucred **));
|
||||
extern void nl_cb_overwrite_send(struct nl_cb *,
|
||||
int (*func)(struct nl_handle *,
|
||||
int (*func)(struct nl_sock *,
|
||||
struct nl_msg *));
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -28,7 +28,7 @@ struct nfnl_ct;
|
|||
extern struct nl_object_ops ct_obj_ops;
|
||||
|
||||
extern struct nfnl_ct * nfnl_ct_alloc(void);
|
||||
extern int nfnl_ct_alloc_cache(struct nl_handle *, struct nl_cache **);
|
||||
extern int nfnl_ct_alloc_cache(struct nl_sock *, struct nl_cache **);
|
||||
|
||||
extern int nfnlmsg_ct_group(struct nlmsghdr *);
|
||||
extern int nfnlmsg_ct_parse(struct nlmsghdr *, struct nfnl_ct **);
|
||||
|
@ -36,19 +36,19 @@ extern int nfnlmsg_ct_parse(struct nlmsghdr *, struct nfnl_ct **);
|
|||
extern void nfnl_ct_get(struct nfnl_ct *);
|
||||
extern void nfnl_ct_put(struct nfnl_ct *);
|
||||
|
||||
extern int nfnl_ct_dump_request(struct nl_handle *);
|
||||
extern int nfnl_ct_dump_request(struct nl_sock *);
|
||||
|
||||
extern int nfnl_ct_build_add_request(const struct nfnl_ct *, int,
|
||||
struct nl_msg **);
|
||||
extern int nfnl_ct_add(struct nl_handle *, const struct nfnl_ct *, int);
|
||||
extern int nfnl_ct_add(struct nl_sock *, const struct nfnl_ct *, int);
|
||||
|
||||
extern int nfnl_ct_build_delete_request(const struct nfnl_ct *, int,
|
||||
struct nl_msg **);
|
||||
extern int nfnl_ct_delete(struct nl_handle *, const struct nfnl_ct *, int);
|
||||
extern int nfnl_ct_delete(struct nl_sock *, const struct nfnl_ct *, int);
|
||||
|
||||
extern int nfnl_ct_build_query_request(const struct nfnl_ct *, int,
|
||||
struct nl_msg **);
|
||||
extern int nfnl_ct_query(struct nl_handle *, const struct nfnl_ct *, int);
|
||||
extern int nfnl_ct_query(struct nl_sock *, const struct nfnl_ct *, int);
|
||||
|
||||
extern void nfnl_ct_set_family(struct nfnl_ct *, uint8_t);
|
||||
extern uint8_t nfnl_ct_get_family(const struct nfnl_ct *);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct nl_handle;
|
||||
struct nl_sock;
|
||||
struct nlmsghdr;
|
||||
struct nfnl_log;
|
||||
|
||||
|
@ -84,22 +84,22 @@ extern char * nfnl_log_flags2str(unsigned int, char *, size_t);
|
|||
extern unsigned int nfnl_log_str2flags(const char *);
|
||||
|
||||
extern int nfnl_log_build_pf_bind(uint8_t, struct nl_msg **);
|
||||
extern int nfnl_log_pf_bind(struct nl_handle *, uint8_t);
|
||||
extern int nfnl_log_pf_bind(struct nl_sock *, uint8_t);
|
||||
|
||||
extern int nfnl_log_build_pf_unbind(uint8_t, struct nl_msg **);
|
||||
extern int nfnl_log_pf_unbind(struct nl_handle *, uint8_t);
|
||||
extern int nfnl_log_pf_unbind(struct nl_sock *, uint8_t);
|
||||
|
||||
extern int nfnl_log_build_create_request(const struct nfnl_log *,
|
||||
struct nl_msg **);
|
||||
extern int nfnl_log_create(struct nl_handle *, const struct nfnl_log *);
|
||||
extern int nfnl_log_create(struct nl_sock *, const struct nfnl_log *);
|
||||
|
||||
extern int nfnl_log_build_change_request(const struct nfnl_log *,
|
||||
struct nl_msg **);
|
||||
extern int nfnl_log_change(struct nl_handle *, const struct nfnl_log *);
|
||||
extern int nfnl_log_change(struct nl_sock *, const struct nfnl_log *);
|
||||
|
||||
extern int nfnl_log_build_delete_request(const struct nfnl_log *,
|
||||
struct nl_msg **);
|
||||
extern int nfnl_log_delete(struct nl_handle *, const struct nfnl_log *);
|
||||
extern int nfnl_log_delete(struct nl_sock *, const struct nfnl_log *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct nl_handle;
|
||||
struct nlmsghdr;
|
||||
struct nfnl_log_msg;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
|
||||
* Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
|
||||
* Copyright (c) 2007 Philip Craig <philipc@snapgear.com>
|
||||
* Copyright (c) 2007 Secure Computing Corporation
|
||||
*/
|
||||
|
@ -23,14 +23,14 @@ extern "C" {
|
|||
#define NFNL_HDRLEN NLMSG_ALIGN(sizeof(struct nfgenmsg))
|
||||
#define NFNLMSG_TYPE(subsys, subtype) (((subsys) << 8) | (subtype))
|
||||
|
||||
extern int nfnl_connect(struct nl_handle *);
|
||||
extern int nfnl_connect(struct nl_sock *);
|
||||
|
||||
extern uint8_t nfnlmsg_subsys(struct nlmsghdr *);
|
||||
extern uint8_t nfnlmsg_subtype(struct nlmsghdr *);
|
||||
extern uint8_t nfnlmsg_family(struct nlmsghdr *);
|
||||
extern uint16_t nfnlmsg_res_id(struct nlmsghdr *);
|
||||
|
||||
extern int nfnl_send_simple(struct nl_handle *, uint8_t, uint8_t,
|
||||
extern int nfnl_send_simple(struct nl_sock *, uint8_t, uint8_t,
|
||||
int, uint8_t, uint16_t);
|
||||
extern struct nl_msg * nfnlmsg_alloc_simple(uint8_t, uint8_t, int,
|
||||
uint8_t, uint16_t);
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct nl_handle;
|
||||
struct nl_sock;
|
||||
struct nlmsghdr;
|
||||
struct nfnl_queue;
|
||||
|
||||
|
@ -60,24 +60,24 @@ extern int nfnl_queue_test_copy_range(const struct nfnl_queue *);
|
|||
extern uint32_t nfnl_queue_get_copy_range(const struct nfnl_queue *);
|
||||
|
||||
extern int nfnl_queue_build_pf_bind(uint8_t, struct nl_msg **);
|
||||
extern int nfnl_queue_pf_bind(struct nl_handle *, uint8_t);
|
||||
extern int nfnl_queue_pf_bind(struct nl_sock *, uint8_t);
|
||||
|
||||
extern int nfnl_queue_build_pf_unbind(uint8_t, struct nl_msg **);
|
||||
extern int nfnl_queue_pf_unbind(struct nl_handle *, uint8_t);
|
||||
extern int nfnl_queue_pf_unbind(struct nl_sock *, uint8_t);
|
||||
|
||||
extern int nfnl_queue_build_create_request(const struct nfnl_queue *,
|
||||
struct nl_msg **);
|
||||
extern int nfnl_queue_create(struct nl_handle *,
|
||||
extern int nfnl_queue_create(struct nl_sock *,
|
||||
const struct nfnl_queue *);
|
||||
|
||||
extern int nfnl_queue_build_change_request(const struct nfnl_queue *,
|
||||
struct nl_msg **);
|
||||
extern int nfnl_queue_change(struct nl_handle *,
|
||||
extern int nfnl_queue_change(struct nl_sock *,
|
||||
const struct nfnl_queue *);
|
||||
|
||||
extern int nfnl_queue_build_delete_request(const struct nfnl_queue *,
|
||||
struct nl_msg **);
|
||||
extern int nfnl_queue_delete(struct nl_handle *,
|
||||
extern int nfnl_queue_delete(struct nl_sock *,
|
||||
const struct nfnl_queue *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct nl_handle;
|
||||
struct nl_sock;
|
||||
struct nlmsghdr;
|
||||
struct nfnl_queue_msg;
|
||||
|
||||
|
@ -91,7 +91,7 @@ extern int nfnl_queue_msg_test_verdict(const struct nfnl_queue_msg *);
|
|||
extern unsigned int nfnl_queue_msg_get_verdict(const struct nfnl_queue_msg *);
|
||||
|
||||
extern struct nl_msg * nfnl_queue_msg_build_verdict(const struct nfnl_queue_msg *);
|
||||
extern int nfnl_queue_msg_send_verdict(struct nl_handle *,
|
||||
extern int nfnl_queue_msg_send_verdict(struct nl_sock *,
|
||||
const struct nfnl_queue_msg *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -39,29 +39,29 @@ extern int nl_debug;
|
|||
extern struct nl_dump_params nl_debug_dp;
|
||||
|
||||
/* Connection Management */
|
||||
extern int nl_connect(struct nl_handle *, int);
|
||||
extern void nl_close(struct nl_handle *);
|
||||
extern int nl_connect(struct nl_sock *, int);
|
||||
extern void nl_close(struct nl_sock *);
|
||||
|
||||
/* Send */
|
||||
extern int nl_sendto(struct nl_handle *, void *, size_t);
|
||||
extern int nl_sendmsg(struct nl_handle *, struct nl_msg *,
|
||||
extern int nl_sendto(struct nl_sock *, void *, size_t);
|
||||
extern int nl_sendmsg(struct nl_sock *, struct nl_msg *,
|
||||
struct msghdr *);
|
||||
extern int nl_send(struct nl_handle *, struct nl_msg *);
|
||||
extern int nl_send_auto_complete(struct nl_handle *,
|
||||
extern int nl_send(struct nl_sock *, struct nl_msg *);
|
||||
extern int nl_send_auto_complete(struct nl_sock *,
|
||||
struct nl_msg *);
|
||||
extern int nl_send_simple(struct nl_handle *, int, int,
|
||||
extern int nl_send_simple(struct nl_sock *, int, int,
|
||||
void *, size_t);
|
||||
|
||||
/* Receive */
|
||||
extern int nl_recv(struct nl_handle *,
|
||||
extern int nl_recv(struct nl_sock *,
|
||||
struct sockaddr_nl *, unsigned char **,
|
||||
struct ucred **);
|
||||
|
||||
extern int nl_recvmsgs(struct nl_handle *, struct nl_cb *);
|
||||
extern int nl_recvmsgs(struct nl_sock *, struct nl_cb *);
|
||||
|
||||
extern int nl_recvmsgs_default(struct nl_handle *);
|
||||
extern int nl_recvmsgs_default(struct nl_sock *);
|
||||
|
||||
extern int nl_wait_for_ack(struct nl_handle *);
|
||||
extern int nl_wait_for_ack(struct nl_sock *);
|
||||
|
||||
/* Netlink Family Translations */
|
||||
extern char * nl_nlfamily2str(int, char *, size_t);
|
||||
|
|
|
@ -28,15 +28,15 @@ struct rtnl_addr;
|
|||
extern struct rtnl_addr *rtnl_addr_alloc(void);
|
||||
extern void rtnl_addr_put(struct rtnl_addr *);
|
||||
|
||||
extern int rtnl_addr_alloc_cache(struct nl_handle *, struct nl_cache **);
|
||||
extern int rtnl_addr_alloc_cache(struct nl_sock *, struct nl_cache **);
|
||||
|
||||
extern int rtnl_addr_build_add_request(struct rtnl_addr *, int,
|
||||
struct nl_msg **);
|
||||
extern int rtnl_addr_add(struct nl_handle *, struct rtnl_addr *, int);
|
||||
extern int rtnl_addr_add(struct nl_sock *, struct rtnl_addr *, int);
|
||||
|
||||
extern int rtnl_addr_build_delete_request(struct rtnl_addr *, int,
|
||||
struct nl_msg **);
|
||||
extern int rtnl_addr_delete(struct nl_handle *,
|
||||
extern int rtnl_addr_delete(struct nl_sock *,
|
||||
struct rtnl_addr *, int);
|
||||
|
||||
extern char * rtnl_addr_flags2str(int, char *, size_t);
|
||||
|
|
|
@ -26,7 +26,7 @@ extern struct nl_object_ops class_obj_ops;
|
|||
|
||||
extern struct rtnl_class * rtnl_class_alloc(void);
|
||||
extern void rtnl_class_put(struct rtnl_class *);
|
||||
extern int rtnl_class_alloc_cache(struct nl_handle *, int,
|
||||
extern int rtnl_class_alloc_cache(struct nl_sock *, int,
|
||||
struct nl_cache **);
|
||||
|
||||
/* leaf qdisc access */
|
||||
|
@ -35,7 +35,7 @@ extern struct rtnl_qdisc * rtnl_class_leaf_qdisc(struct rtnl_class *,
|
|||
|
||||
extern int rtnl_class_build_add_request(struct rtnl_class *, int,
|
||||
struct nl_msg **);
|
||||
extern int rtnl_class_add(struct nl_handle *, struct rtnl_class *,
|
||||
extern int rtnl_class_add(struct nl_sock *, struct rtnl_class *,
|
||||
int);
|
||||
|
||||
extern void rtnl_class_set_ifindex(struct rtnl_class *, int);
|
||||
|
|
|
@ -26,18 +26,18 @@ extern struct nl_object_ops cls_obj_ops;
|
|||
extern struct rtnl_cls *rtnl_cls_alloc(void);
|
||||
extern void rtnl_cls_put(struct rtnl_cls *);
|
||||
|
||||
extern int rtnl_cls_alloc_cache(struct nl_handle *, int, uint32_t,
|
||||
extern int rtnl_cls_alloc_cache(struct nl_sock *, int, uint32_t,
|
||||
struct nl_cache **);
|
||||
|
||||
extern int rtnl_cls_build_add_request(struct rtnl_cls *, int,
|
||||
struct nl_msg **);
|
||||
extern int rtnl_cls_add(struct nl_handle *, struct rtnl_cls *, int);
|
||||
extern int rtnl_cls_add(struct nl_sock *, struct rtnl_cls *, int);
|
||||
|
||||
extern int rtnl_cls_build_change_request(struct rtnl_cls *, int,
|
||||
struct nl_msg **);
|
||||
extern int rtnl_cls_build_delete_request(struct rtnl_cls *, int,
|
||||
struct nl_msg **);
|
||||
extern int rtnl_cls_delete(struct nl_handle *, struct rtnl_cls *, int);
|
||||
extern int rtnl_cls_delete(struct nl_sock *, struct rtnl_cls *, int);
|
||||
|
||||
extern void rtnl_cls_set_ifindex(struct rtnl_cls *, int);
|
||||
extern void rtnl_cls_set_handle(struct rtnl_cls *, uint32_t);
|
||||
|
|
|
@ -57,7 +57,7 @@ extern void rtnl_link_put(struct rtnl_link *);
|
|||
extern void rtnl_link_free(struct rtnl_link *);
|
||||
|
||||
/* link cache management */
|
||||
extern int rtnl_link_alloc_cache(struct nl_handle *, struct nl_cache **);
|
||||
extern int rtnl_link_alloc_cache(struct nl_sock *, struct nl_cache **);
|
||||
extern struct rtnl_link *rtnl_link_get(struct nl_cache *, int);
|
||||
extern struct rtnl_link *rtnl_link_get_by_name(struct nl_cache *, const char *);
|
||||
|
||||
|
@ -65,7 +65,7 @@ extern struct rtnl_link *rtnl_link_get_by_name(struct nl_cache *, const char *);
|
|||
extern int rtnl_link_build_change_request(struct rtnl_link *,
|
||||
struct rtnl_link *, int,
|
||||
struct nl_msg **);
|
||||
extern int rtnl_link_change(struct nl_handle *, struct rtnl_link *,
|
||||
extern int rtnl_link_change(struct nl_sock *, struct rtnl_link *,
|
||||
struct rtnl_link *, int);
|
||||
|
||||
/* Name <-> Index Translations */
|
||||
|
|
|
@ -25,7 +25,7 @@ struct rtnl_neigh;
|
|||
extern struct rtnl_neigh *rtnl_neigh_alloc(void);
|
||||
extern void rtnl_neigh_put(struct rtnl_neigh *);
|
||||
|
||||
extern int rtnl_neigh_alloc_cache(struct nl_handle *, struct nl_cache **);
|
||||
extern int rtnl_neigh_alloc_cache(struct nl_sock *, struct nl_cache **);
|
||||
extern struct rtnl_neigh *rtnl_neigh_get(struct nl_cache *, int,
|
||||
struct nl_addr *);
|
||||
|
||||
|
@ -35,15 +35,15 @@ extern int rtnl_neigh_str2state(const char *);
|
|||
extern char * rtnl_neigh_flags2str(int, char *, size_t);
|
||||
extern int rtnl_neigh_str2flag(const char *);
|
||||
|
||||
extern int rtnl_neigh_add(struct nl_handle *, struct rtnl_neigh *, int);
|
||||
extern int rtnl_neigh_add(struct nl_sock *, struct rtnl_neigh *, int);
|
||||
extern int rtnl_neigh_build_add_request(struct rtnl_neigh *, int,
|
||||
struct nl_msg **);
|
||||
|
||||
extern int rtnl_neigh_change(struct nl_handle *, struct rtnl_neigh *, int);
|
||||
extern int rtnl_neigh_change(struct nl_sock *, struct rtnl_neigh *, int);
|
||||
extern int rtnl_neigh_build_change_request(struct rtnl_neigh *, int,
|
||||
struct nl_msg **);
|
||||
|
||||
extern int rtnl_neigh_delete(struct nl_handle *, struct rtnl_neigh *, int);
|
||||
extern int rtnl_neigh_delete(struct nl_sock *, struct rtnl_neigh *, int);
|
||||
extern int rtnl_neigh_build_delete_request(struct rtnl_neigh *, int,
|
||||
struct nl_msg **);
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ struct rtnl_neightbl;
|
|||
extern struct rtnl_neightbl *rtnl_neightbl_alloc(void);
|
||||
extern void rtnl_neightbl_put(struct rtnl_neightbl *);
|
||||
extern void rtnl_neightbl_free(struct rtnl_neightbl *);
|
||||
extern int rtnl_neightbl_alloc_cache(struct nl_handle *, struct nl_cache **);
|
||||
extern int rtnl_neightbl_alloc_cache(struct nl_sock *, struct nl_cache **);
|
||||
extern struct rtnl_neightbl *rtnl_neightbl_get(struct nl_cache *,
|
||||
const char *, int);
|
||||
extern void rtnl_neightbl_dump(struct rtnl_neightbl *, FILE *,
|
||||
|
@ -34,7 +34,7 @@ extern void rtnl_neightbl_dump(struct rtnl_neightbl *, FILE *,
|
|||
extern int rtnl_neightbl_build_change_request(struct rtnl_neightbl *,
|
||||
struct rtnl_neightbl *,
|
||||
struct nl_msg **);
|
||||
extern int rtnl_neightbl_change(struct nl_handle *, struct rtnl_neightbl *,
|
||||
extern int rtnl_neightbl_change(struct nl_sock *, struct rtnl_neightbl *,
|
||||
struct rtnl_neightbl *);
|
||||
|
||||
extern void rtnl_neightbl_set_family(struct rtnl_neightbl *, int);
|
||||
|
|
|
@ -27,24 +27,24 @@ extern struct nl_object_ops qdisc_obj_ops;
|
|||
extern struct rtnl_qdisc *rtnl_qdisc_alloc(void);
|
||||
extern void rtnl_qdisc_put(struct rtnl_qdisc *);
|
||||
|
||||
extern int rtnl_qdisc_alloc_cache(struct nl_handle *, struct nl_cache **);
|
||||
extern int rtnl_qdisc_alloc_cache(struct nl_sock *, struct nl_cache **);
|
||||
extern struct rtnl_qdisc *rtnl_qdisc_get(struct nl_cache *, int, uint32_t);
|
||||
extern struct rtnl_qdisc *rtnl_qdisc_get_by_parent(struct nl_cache *,
|
||||
int, uint32_t);
|
||||
|
||||
extern int rtnl_qdisc_build_add_request(struct rtnl_qdisc *, int,
|
||||
struct nl_msg **);
|
||||
extern int rtnl_qdisc_add(struct nl_handle *, struct rtnl_qdisc *, int);
|
||||
extern int rtnl_qdisc_add(struct nl_sock *, struct rtnl_qdisc *, int);
|
||||
|
||||
extern int rtnl_qdisc_build_change_request(struct rtnl_qdisc *,
|
||||
struct rtnl_qdisc *,
|
||||
struct nl_msg **);
|
||||
extern int rtnl_qdisc_change(struct nl_handle *, struct rtnl_qdisc *,
|
||||
extern int rtnl_qdisc_change(struct nl_sock *, struct rtnl_qdisc *,
|
||||
struct rtnl_qdisc *);
|
||||
|
||||
extern int rtnl_qdisc_build_delete_request(struct rtnl_qdisc *,
|
||||
struct nl_msg **);
|
||||
extern int rtnl_qdisc_delete(struct nl_handle *, struct rtnl_qdisc *);
|
||||
extern int rtnl_qdisc_delete(struct nl_sock *, struct rtnl_qdisc *);
|
||||
|
||||
extern void rtnl_qdisc_set_ifindex(struct rtnl_qdisc *, int);
|
||||
extern int rtnl_qdisc_get_ifindex(struct rtnl_qdisc *);
|
||||
|
|
|
@ -44,7 +44,7 @@ extern struct nl_object_ops route_obj_ops;
|
|||
|
||||
extern struct rtnl_route * rtnl_route_alloc(void);
|
||||
extern void rtnl_route_put(struct rtnl_route *);
|
||||
extern int rtnl_route_alloc_cache(struct nl_handle *, int, int,
|
||||
extern int rtnl_route_alloc_cache(struct nl_sock *, int, int,
|
||||
struct nl_cache **);
|
||||
|
||||
extern void rtnl_route_get(struct rtnl_route *);
|
||||
|
@ -55,10 +55,10 @@ extern int rtnl_route_build_msg(struct nl_msg *, struct rtnl_route *);
|
|||
|
||||
extern int rtnl_route_build_add_request(struct rtnl_route *, int,
|
||||
struct nl_msg **);
|
||||
extern int rtnl_route_add(struct nl_handle *, struct rtnl_route *, int);
|
||||
extern int rtnl_route_add(struct nl_sock *, struct rtnl_route *, int);
|
||||
extern int rtnl_route_build_del_request(struct rtnl_route *, int,
|
||||
struct nl_msg **);
|
||||
extern int rtnl_route_delete(struct nl_handle *, struct rtnl_route *, int);
|
||||
extern int rtnl_route_delete(struct nl_sock *, struct rtnl_route *, int);
|
||||
|
||||
extern void rtnl_route_set_table(struct rtnl_route *, uint32_t);
|
||||
extern uint32_t rtnl_route_get_table(struct rtnl_route *);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
|
||||
* Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
|
||||
*/
|
||||
|
||||
#ifndef NETLINK_RTNL_H_
|
||||
|
@ -49,7 +49,7 @@ extern "C" {
|
|||
|
||||
|
||||
/* General */
|
||||
extern int nl_rtgen_request(struct nl_handle *, int, int, int);
|
||||
extern int nl_rtgen_request(struct nl_sock *, int, int, int);
|
||||
|
||||
/* Routing Type Translations */
|
||||
extern char * nl_rtntype2str(int, char *, size_t);
|
||||
|
|
|
@ -27,16 +27,16 @@ struct rtnl_rule;
|
|||
extern struct rtnl_rule * rtnl_rule_alloc(void);
|
||||
extern void rtnl_rule_put(struct rtnl_rule *);
|
||||
|
||||
extern int rtnl_rule_alloc_cache(struct nl_handle *, int,
|
||||
extern int rtnl_rule_alloc_cache(struct nl_sock *, int,
|
||||
struct nl_cache **);
|
||||
extern void rtnl_rule_dump(struct rtnl_rule *, FILE *, struct nl_dump_params *);
|
||||
|
||||
extern int rtnl_rule_build_add_request(struct rtnl_rule *, int,
|
||||
struct nl_msg **);
|
||||
extern int rtnl_rule_add(struct nl_handle *, struct rtnl_rule *, int);
|
||||
extern int rtnl_rule_add(struct nl_sock *, struct rtnl_rule *, int);
|
||||
extern int rtnl_rule_build_delete_request(struct rtnl_rule *, int,
|
||||
struct nl_msg **);
|
||||
extern int rtnl_rule_delete(struct nl_handle *, struct rtnl_rule *, int);
|
||||
extern int rtnl_rule_delete(struct nl_sock *, struct rtnl_rule *, int);
|
||||
|
||||
|
||||
/* attribute modification */
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
|
||||
* Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
|
||||
*/
|
||||
|
||||
#ifndef NETLINK_SOCKET_H_
|
||||
|
@ -19,45 +19,48 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern struct nl_handle * nl_handle_alloc(void);
|
||||
extern struct nl_handle * nl_handle_alloc_cb(struct nl_cb *);
|
||||
extern void nl_handle_destroy(struct nl_handle *);
|
||||
/* backwards compatibility for now */
|
||||
#define nl_handle nl_sock
|
||||
|
||||
extern uint32_t nl_socket_get_local_port(struct nl_handle *);
|
||||
extern void nl_socket_set_local_port(struct nl_handle *,
|
||||
extern struct nl_sock * nl_socket_alloc(void);
|
||||
extern struct nl_sock * nl_socket_alloc_cb(struct nl_cb *);
|
||||
extern void nl_socket_free(struct nl_sock *);
|
||||
|
||||
extern uint32_t nl_socket_get_local_port(struct nl_sock *);
|
||||
extern void nl_socket_set_local_port(struct nl_sock *,
|
||||
uint32_t);
|
||||
|
||||
extern int nl_socket_add_membership(struct nl_handle *,
|
||||
extern int nl_socket_add_membership(struct nl_sock *,
|
||||
int);
|
||||
extern int nl_socket_drop_membership(struct nl_handle *,
|
||||
extern int nl_socket_drop_membership(struct nl_sock *,
|
||||
int);
|
||||
extern void nl_join_groups(struct nl_handle *, int);
|
||||
extern void nl_join_groups(struct nl_sock *, int);
|
||||
|
||||
extern uint32_t nl_socket_get_peer_port(struct nl_handle *);
|
||||
extern void nl_socket_set_peer_port(struct nl_handle *,
|
||||
extern uint32_t nl_socket_get_peer_port(struct nl_sock *);
|
||||
extern void nl_socket_set_peer_port(struct nl_sock *,
|
||||
uint32_t);
|
||||
|
||||
extern struct nl_cb * nl_socket_get_cb(struct nl_handle *);
|
||||
extern void nl_socket_set_cb(struct nl_handle *,
|
||||
extern struct nl_cb * nl_socket_get_cb(struct nl_sock *);
|
||||
extern void nl_socket_set_cb(struct nl_sock *,
|
||||
struct nl_cb *);
|
||||
extern int nl_socket_modify_cb(struct nl_handle *,
|
||||
extern int nl_socket_modify_cb(struct nl_sock *,
|
||||
enum nl_cb_type,
|
||||
enum nl_cb_kind,
|
||||
nl_recvmsg_msg_cb_t,
|
||||
void *);
|
||||
|
||||
extern int nl_set_buffer_size(struct nl_handle *,
|
||||
extern int nl_set_buffer_size(struct nl_sock *,
|
||||
int, int);
|
||||
extern int nl_set_passcred(struct nl_handle *, int);
|
||||
extern int nl_socket_recv_pktinfo(struct nl_handle *, int);
|
||||
extern int nl_set_passcred(struct nl_sock *, int);
|
||||
extern int nl_socket_recv_pktinfo(struct nl_sock *, int);
|
||||
|
||||
extern void nl_disable_sequence_check(struct nl_handle *);
|
||||
extern unsigned int nl_socket_use_seq(struct nl_handle *);
|
||||
extern void nl_disable_sequence_check(struct nl_sock *);
|
||||
extern unsigned int nl_socket_use_seq(struct nl_sock *);
|
||||
|
||||
extern int nl_socket_get_fd(struct nl_handle *);
|
||||
extern int nl_socket_set_nonblocking(struct nl_handle *);
|
||||
extern void nl_socket_enable_msg_peek(struct nl_handle *);
|
||||
extern void nl_socket_disable_msg_peek(struct nl_handle *);
|
||||
extern int nl_socket_get_fd(struct nl_sock *);
|
||||
extern int nl_socket_set_nonblocking(struct nl_sock *);
|
||||
extern void nl_socket_enable_msg_peek(struct nl_sock *);
|
||||
extern void nl_socket_disable_msg_peek(struct nl_sock *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
34
lib/cache.c
34
lib/cache.c
|
@ -186,7 +186,7 @@ struct nl_cache *nl_cache_alloc(struct nl_cache_ops *ops)
|
|||
return cache;
|
||||
}
|
||||
|
||||
int nl_cache_alloc_and_fill(struct nl_cache_ops *ops, struct nl_handle *sock,
|
||||
int nl_cache_alloc_and_fill(struct nl_cache_ops *ops, struct nl_sock *sock,
|
||||
struct nl_cache **result)
|
||||
{
|
||||
struct nl_cache *cache;
|
||||
|
@ -427,7 +427,7 @@ struct nl_object *nl_cache_search(struct nl_cache *cache,
|
|||
|
||||
/**
|
||||
* Request a full dump from the kernel to fill a cache
|
||||
* @arg handle Netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg cache Cache subjected to be filled.
|
||||
*
|
||||
* Send a dumping request to the kernel causing it to dump all objects
|
||||
|
@ -436,7 +436,7 @@ struct nl_object *nl_cache_search(struct nl_cache *cache,
|
|||
* Use nl_cache_pickup() to read the objects from the socket and fill them
|
||||
* into a cache.
|
||||
*/
|
||||
int nl_cache_request_full_dump(struct nl_handle *handle, struct nl_cache *cache)
|
||||
int nl_cache_request_full_dump(struct nl_sock *sk, struct nl_cache *cache)
|
||||
{
|
||||
NL_DBG(2, "Requesting dump from kernel for cache %p <%s>...\n",
|
||||
cache, nl_cache_name(cache));
|
||||
|
@ -444,7 +444,7 @@ int nl_cache_request_full_dump(struct nl_handle *handle, struct nl_cache *cache)
|
|||
if (cache->c_ops->co_request_update == NULL)
|
||||
return -NLE_OPNOTSUPP;
|
||||
|
||||
return cache->c_ops->co_request_update(cache, handle);
|
||||
return cache->c_ops->co_request_update(cache, sk);
|
||||
}
|
||||
|
||||
/** @cond SKIP */
|
||||
|
@ -461,7 +461,7 @@ static int update_msg_parser(struct nl_msg *msg, void *arg)
|
|||
}
|
||||
/** @endcond */
|
||||
|
||||
int __cache_pickup(struct nl_handle *handle, struct nl_cache *cache,
|
||||
int __cache_pickup(struct nl_sock *sk, struct nl_cache *cache,
|
||||
struct nl_parser_param *param)
|
||||
{
|
||||
int err;
|
||||
|
@ -474,13 +474,13 @@ int __cache_pickup(struct nl_handle *handle, struct nl_cache *cache,
|
|||
NL_DBG(1, "Picking up answer for cache %p <%s>...\n",
|
||||
cache, nl_cache_name(cache));
|
||||
|
||||
cb = nl_cb_clone(handle->h_cb);
|
||||
cb = nl_cb_clone(sk->s_cb);
|
||||
if (cb == NULL)
|
||||
return -NLE_NOMEM;
|
||||
|
||||
nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, update_msg_parser, &x);
|
||||
|
||||
err = nl_recvmsgs(handle, cb);
|
||||
err = nl_recvmsgs(sk, cb);
|
||||
if (err < 0)
|
||||
NL_DBG(2, "While picking up for %p <%s>, recvmsgs() returned " \
|
||||
"%d: %s", cache, nl_cache_name(cache),
|
||||
|
@ -498,7 +498,7 @@ static int pickup_cb(struct nl_object *c, struct nl_parser_param *p)
|
|||
|
||||
/**
|
||||
* Pickup a netlink dump response and put it into a cache.
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg cache Cache to put items into.
|
||||
*
|
||||
* Waits for netlink messages to arrive, parses them and puts them into
|
||||
|
@ -506,14 +506,14 @@ static int pickup_cb(struct nl_object *c, struct nl_parser_param *p)
|
|||
*
|
||||
* @return 0 on success or a negative error code.
|
||||
*/
|
||||
int nl_cache_pickup(struct nl_handle *handle, struct nl_cache *cache)
|
||||
int nl_cache_pickup(struct nl_sock *sk, struct nl_cache *cache)
|
||||
{
|
||||
struct nl_parser_param p = {
|
||||
.pp_cb = pickup_cb,
|
||||
.pp_arg = cache,
|
||||
};
|
||||
|
||||
return __cache_pickup(handle, cache, &p);
|
||||
return __cache_pickup(sk, cache, &p);
|
||||
}
|
||||
|
||||
static int cache_include(struct nl_cache *cache, struct nl_object *obj,
|
||||
|
@ -578,7 +578,7 @@ static int resync_cb(struct nl_object *c, struct nl_parser_param *p)
|
|||
return nl_cache_include(ca->ca_cache, c, ca->ca_change);
|
||||
}
|
||||
|
||||
int nl_cache_resync(struct nl_handle *handle, struct nl_cache *cache,
|
||||
int nl_cache_resync(struct nl_sock *sk, struct nl_cache *cache,
|
||||
change_func_t change_cb)
|
||||
{
|
||||
struct nl_object *obj, *next;
|
||||
|
@ -597,11 +597,11 @@ int nl_cache_resync(struct nl_handle *handle, struct nl_cache *cache,
|
|||
/* Mark all objects so we can see if some of them are obsolete */
|
||||
nl_cache_mark_all(cache);
|
||||
|
||||
err = nl_cache_request_full_dump(handle, cache);
|
||||
err = nl_cache_request_full_dump(sk, cache);
|
||||
if (err < 0)
|
||||
goto errout;
|
||||
|
||||
err = __cache_pickup(handle, cache, &p);
|
||||
err = __cache_pickup(sk, cache, &p);
|
||||
if (err < 0)
|
||||
goto errout;
|
||||
|
||||
|
@ -669,7 +669,7 @@ int nl_cache_parse_and_add(struct nl_cache *cache, struct nl_msg *msg)
|
|||
|
||||
/**
|
||||
* (Re)fill a cache with the contents in the kernel.
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg cache cache to update
|
||||
*
|
||||
* Clears the specified cache and fills it with the current state in
|
||||
|
@ -677,11 +677,11 @@ int nl_cache_parse_and_add(struct nl_cache *cache, struct nl_msg *msg)
|
|||
*
|
||||
* @return 0 or a negative error code.
|
||||
*/
|
||||
int nl_cache_refill(struct nl_handle *handle, struct nl_cache *cache)
|
||||
int nl_cache_refill(struct nl_sock *sk, struct nl_cache *cache)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = nl_cache_request_full_dump(handle, cache);
|
||||
err = nl_cache_request_full_dump(sk, cache);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
|
@ -689,7 +689,7 @@ int nl_cache_refill(struct nl_handle *handle, struct nl_cache *cache)
|
|||
cache, nl_cache_name(cache));
|
||||
nl_cache_clear(cache);
|
||||
|
||||
return nl_cache_pickup(handle, cache);
|
||||
return nl_cache_pickup(sk, cache);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -140,26 +140,26 @@ found:
|
|||
|
||||
/**
|
||||
* Allocate new cache manager
|
||||
* @arg handle Netlink socket/handle to be used
|
||||
* @arg sk Netlink socket.
|
||||
* @arg protocol Netlink Protocol this manager is used for
|
||||
* @arg flags Flags
|
||||
*
|
||||
* @return Newly allocated cache manager or NULL on failure.
|
||||
*/
|
||||
int nl_cache_mngr_alloc(struct nl_handle *handle, int protocol, int flags,
|
||||
int nl_cache_mngr_alloc(struct nl_sock *sk, int protocol, int flags,
|
||||
struct nl_cache_mngr **result)
|
||||
{
|
||||
struct nl_cache_mngr *mngr;
|
||||
int err = -NLE_NOMEM;
|
||||
|
||||
if (handle == NULL)
|
||||
if (sk == NULL)
|
||||
BUG();
|
||||
|
||||
mngr = calloc(1, sizeof(*mngr));
|
||||
if (!mngr)
|
||||
goto errout;
|
||||
|
||||
mngr->cm_handle = handle;
|
||||
mngr->cm_handle = sk;
|
||||
mngr->cm_nassocs = 32;
|
||||
mngr->cm_protocol = protocol;
|
||||
mngr->cm_flags = flags;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
* Almost all subsystem provide a function to allocate a new cache
|
||||
* of some form. The function usually looks like this:
|
||||
* @code
|
||||
* struct nl_cache *<object name>_alloc_cache(struct nl_handle *handle)
|
||||
* struct nl_cache *<object name>_alloc_cache(struct nl_sock *sk);
|
||||
* @endcode
|
||||
*
|
||||
* These functions allocate a new cache for the own object type,
|
||||
|
|
|
@ -251,7 +251,7 @@ errout:
|
|||
|
||||
/**
|
||||
* Perform FIB Lookup
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg req Lookup request object.
|
||||
* @arg cache Cache for result.
|
||||
*
|
||||
|
@ -260,7 +260,7 @@ errout:
|
|||
*
|
||||
* @return 0 on success or a negative error code.
|
||||
*/
|
||||
int flnl_lookup(struct nl_handle *handle, struct flnl_request *req,
|
||||
int flnl_lookup(struct nl_sock *sk, struct flnl_request *req,
|
||||
struct nl_cache *cache)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
|
@ -269,12 +269,12 @@ int flnl_lookup(struct nl_handle *handle, struct flnl_request *req,
|
|||
if ((err = flnl_lookup_build_request(req, 0, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
err = nl_send_auto_complete(handle, msg);
|
||||
err = nl_send_auto_complete(sk, msg);
|
||||
nlmsg_free(msg);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
return nl_cache_pickup(handle, cache);
|
||||
return nl_cache_pickup(sk, cache);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
static struct nl_cache_ops genl_ctrl_ops;
|
||||
/** @endcond */
|
||||
|
||||
static int ctrl_request_update(struct nl_cache *c, struct nl_handle *h)
|
||||
static int ctrl_request_update(struct nl_cache *c, struct nl_sock *h)
|
||||
{
|
||||
return genl_send_simple(h, GENL_ID_CTRL, CTRL_CMD_GETFAMILY,
|
||||
CTRL_VERSION, NLM_F_DUMP);
|
||||
|
@ -143,7 +143,7 @@ errout:
|
|||
* @{
|
||||
*/
|
||||
|
||||
int genl_ctrl_alloc_cache(struct nl_handle *sock, struct nl_cache **result)
|
||||
int genl_ctrl_alloc_cache(struct nl_sock *sock, struct nl_cache **result)
|
||||
{
|
||||
return nl_cache_alloc_and_fill(&genl_ctrl_ops, sock, result);
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ struct genl_family *genl_ctrl_search_by_name(struct nl_cache *cache,
|
|||
|
||||
/**
|
||||
* Resolve generic netlink family name to its identifier
|
||||
* @arg handle Netlink Handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg name Name of generic netlink family
|
||||
*
|
||||
* Resolves the generic netlink family name to its identifer and returns
|
||||
|
@ -224,13 +224,13 @@ struct genl_family *genl_ctrl_search_by_name(struct nl_cache *cache,
|
|||
*
|
||||
* @return A positive identifier or a negative error code.
|
||||
*/
|
||||
int genl_ctrl_resolve(struct nl_handle *handle, const char *name)
|
||||
int genl_ctrl_resolve(struct nl_sock *sk, const char *name)
|
||||
{
|
||||
struct nl_cache *cache;
|
||||
struct genl_family *family;
|
||||
int err;
|
||||
|
||||
if ((err = genl_ctrl_alloc_cache(handle, &cache)) < 0)
|
||||
if ((err = genl_ctrl_alloc_cache(sk, &cache)) < 0)
|
||||
return err;
|
||||
|
||||
family = genl_ctrl_search_by_name(cache, name);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
|
||||
* Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -38,12 +38,12 @@
|
|||
* #include <netlink/genl/genl.h>
|
||||
* #include <netlink/genl/ctrl.h>
|
||||
*
|
||||
* struct nl_handle *sock;
|
||||
* struct nl_sock *sock;
|
||||
* struct nl_msg *msg;
|
||||
* int family;
|
||||
*
|
||||
* // Allocate a new netlink socket
|
||||
* sock = nl_handle_alloc();
|
||||
* sock = nl_socket_alloc();
|
||||
*
|
||||
* // Connect to generic netlink socket on kernel side
|
||||
* genl_connect(sock);
|
||||
|
@ -100,9 +100,9 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
int genl_connect(struct nl_handle *handle)
|
||||
int genl_connect(struct nl_sock *sk)
|
||||
{
|
||||
return nl_connect(handle, NETLINK_GENERIC);
|
||||
return nl_connect(sk, NETLINK_GENERIC);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -114,7 +114,7 @@ int genl_connect(struct nl_handle *handle)
|
|||
|
||||
/**
|
||||
* Send trivial generic netlink message
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg family Generic netlink family
|
||||
* @arg cmd Command
|
||||
* @arg version Version
|
||||
|
@ -125,7 +125,7 @@ int genl_connect(struct nl_handle *handle)
|
|||
*
|
||||
* @return 0 on success or a negative error code.
|
||||
*/
|
||||
int genl_send_simple(struct nl_handle *handle, int family, int cmd,
|
||||
int genl_send_simple(struct nl_sock *sk, int family, int cmd,
|
||||
int version, int flags)
|
||||
{
|
||||
struct genlmsghdr hdr = {
|
||||
|
@ -133,7 +133,7 @@ int genl_send_simple(struct nl_handle *handle, int family, int cmd,
|
|||
.version = version,
|
||||
};
|
||||
|
||||
return nl_send_simple(handle, family, flags, &hdr, sizeof(hdr));
|
||||
return nl_send_simple(sk, family, flags, &hdr, sizeof(hdr));
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -234,12 +234,12 @@ static int __genl_ops_resolve(struct nl_cache *ctrl, struct genl_ops *ops)
|
|||
return -NLE_OBJ_NOTFOUND;
|
||||
}
|
||||
|
||||
int genl_ops_resolve(struct nl_handle *handle, struct genl_ops *ops)
|
||||
int genl_ops_resolve(struct nl_sock *sk, struct genl_ops *ops)
|
||||
{
|
||||
struct nl_cache *ctrl;
|
||||
int err;
|
||||
|
||||
if ((err = genl_ctrl_alloc_cache(handle, &ctrl)) < 0)
|
||||
if ((err = genl_ctrl_alloc_cache(sk, &ctrl)) < 0)
|
||||
goto errout;
|
||||
|
||||
err = __genl_ops_resolve(ctrl, ops);
|
||||
|
@ -249,13 +249,13 @@ errout:
|
|||
return err;
|
||||
}
|
||||
|
||||
int genl_mngt_resolve(struct nl_handle *handle)
|
||||
int genl_mngt_resolve(struct nl_sock *sk)
|
||||
{
|
||||
struct nl_cache *ctrl;
|
||||
struct genl_ops *ops;
|
||||
int err = 0;
|
||||
|
||||
if ((err = genl_ctrl_alloc_cache(handle, &ctrl)) < 0)
|
||||
if ((err = genl_ctrl_alloc_cache(sk, &ctrl)) < 0)
|
||||
goto errout;
|
||||
|
||||
nl_list_for_each_entry(ops, &genl_ops_list, o_list) {
|
||||
|
|
|
@ -412,7 +412,7 @@ int nl_cb_err(struct nl_cb *cb, enum nl_cb_kind kind,
|
|||
* @arg func replacement callback for nl_recvmsgs()
|
||||
*/
|
||||
void nl_cb_overwrite_recvmsgs(struct nl_cb *cb,
|
||||
int (*func)(struct nl_handle *, struct nl_cb *))
|
||||
int (*func)(struct nl_sock *, struct nl_cb *))
|
||||
{
|
||||
cb->cb_recvmsgs_ow = func;
|
||||
}
|
||||
|
@ -423,7 +423,7 @@ void nl_cb_overwrite_recvmsgs(struct nl_cb *cb,
|
|||
* @arg func replacement callback for nl_recv()
|
||||
*/
|
||||
void nl_cb_overwrite_recv(struct nl_cb *cb,
|
||||
int (*func)(struct nl_handle *, struct sockaddr_nl *,
|
||||
int (*func)(struct nl_sock *, struct sockaddr_nl *,
|
||||
unsigned char **, struct ucred **))
|
||||
{
|
||||
cb->cb_recv_ow = func;
|
||||
|
@ -435,7 +435,7 @@ void nl_cb_overwrite_recv(struct nl_cb *cb,
|
|||
* @arg func replacement callback for nl_send()
|
||||
*/
|
||||
void nl_cb_overwrite_send(struct nl_cb *cb,
|
||||
int (*func)(struct nl_handle *, struct nl_msg *))
|
||||
int (*func)(struct nl_sock *, struct nl_msg *))
|
||||
{
|
||||
cb->cb_send_ow = func;
|
||||
}
|
||||
|
|
|
@ -374,15 +374,15 @@ errout:
|
|||
return err;
|
||||
}
|
||||
|
||||
int nfnl_ct_dump_request(struct nl_handle *h)
|
||||
int nfnl_ct_dump_request(struct nl_sock *sk)
|
||||
{
|
||||
return nfnl_send_simple(h, NFNL_SUBSYS_CTNETLINK, IPCTNL_MSG_CT_GET,
|
||||
return nfnl_send_simple(sk, NFNL_SUBSYS_CTNETLINK, IPCTNL_MSG_CT_GET,
|
||||
NLM_F_DUMP, AF_UNSPEC, 0);
|
||||
}
|
||||
|
||||
static int ct_request_update(struct nl_cache *c, struct nl_handle *h)
|
||||
static int ct_request_update(struct nl_cache *cache, struct nl_sock *sk)
|
||||
{
|
||||
return nfnl_ct_dump_request(h);
|
||||
return nfnl_ct_dump_request(sk);
|
||||
}
|
||||
|
||||
static int nfnl_ct_build_tuple(struct nl_msg *msg, const struct nfnl_ct *ct,
|
||||
|
@ -480,7 +480,7 @@ int nfnl_ct_build_add_request(const struct nfnl_ct *ct, int flags,
|
|||
return nfnl_ct_build_message(ct, IPCTNL_MSG_CT_NEW, flags, result);
|
||||
}
|
||||
|
||||
int nfnl_ct_add(struct nl_handle *h, const struct nfnl_ct *ct, int flags)
|
||||
int nfnl_ct_add(struct nl_sock *sk, const struct nfnl_ct *ct, int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -488,12 +488,12 @@ int nfnl_ct_add(struct nl_handle *h, const struct nfnl_ct *ct, int flags)
|
|||
if ((err = nfnl_ct_build_add_request(ct, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
err = nl_send_auto_complete(h, msg);
|
||||
err = nl_send_auto_complete(sk, msg);
|
||||
nlmsg_free(msg);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
return nl_wait_for_ack(h);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
int nfnl_ct_build_delete_request(const struct nfnl_ct *ct, int flags,
|
||||
|
@ -502,7 +502,7 @@ int nfnl_ct_build_delete_request(const struct nfnl_ct *ct, int flags,
|
|||
return nfnl_ct_build_message(ct, IPCTNL_MSG_CT_DELETE, flags, result);
|
||||
}
|
||||
|
||||
int nfnl_ct_del(struct nl_handle *h, const struct nfnl_ct *ct, int flags)
|
||||
int nfnl_ct_del(struct nl_sock *sk, const struct nfnl_ct *ct, int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -510,12 +510,12 @@ int nfnl_ct_del(struct nl_handle *h, const struct nfnl_ct *ct, int flags)
|
|||
if ((err = nfnl_ct_build_delete_request(ct, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
err = nl_send_auto_complete(h, msg);
|
||||
err = nl_send_auto_complete(sk, msg);
|
||||
nlmsg_free(msg);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
return nl_wait_for_ack(h);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
int nfnl_ct_build_query_request(const struct nfnl_ct *ct, int flags,
|
||||
|
@ -524,7 +524,7 @@ int nfnl_ct_build_query_request(const struct nfnl_ct *ct, int flags,
|
|||
return nfnl_ct_build_message(ct, IPCTNL_MSG_CT_GET, flags, result);
|
||||
}
|
||||
|
||||
int nfnl_ct_query(struct nl_handle *h, const struct nfnl_ct *ct, int flags)
|
||||
int nfnl_ct_query(struct nl_sock *sk, const struct nfnl_ct *ct, int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -532,12 +532,12 @@ int nfnl_ct_query(struct nl_handle *h, const struct nfnl_ct *ct, int flags)
|
|||
if ((err = nfnl_ct_build_query_request(ct, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
err = nl_send_auto_complete(h, msg);
|
||||
err = nl_send_auto_complete(sk, msg);
|
||||
nlmsg_free(msg);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
return nl_wait_for_ack(h);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -547,7 +547,7 @@ int nfnl_ct_query(struct nl_handle *h, const struct nfnl_ct *ct, int flags)
|
|||
|
||||
/**
|
||||
* Build a conntrack cache holding all conntrack currently in the kernel
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg result Pointer to store resulting cache.
|
||||
*
|
||||
* Allocates a new cache, initializes it properly and updates it to
|
||||
|
@ -555,9 +555,9 @@ int nfnl_ct_query(struct nl_handle *h, const struct nfnl_ct *ct, int flags)
|
|||
*
|
||||
* @return 0 on success or a negative error code.
|
||||
*/
|
||||
int nfnl_ct_alloc_cache(struct nl_handle *sock, struct nl_cache **result)
|
||||
int nfnl_ct_alloc_cache(struct nl_sock *sk, struct nl_cache **result)
|
||||
{
|
||||
return nl_cache_alloc_and_fill(&nfnl_ct_ops, sock, result);
|
||||
return nl_cache_alloc_and_fill(&nfnl_ct_ops, sk, result);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -54,16 +54,16 @@ nla_put_failure:
|
|||
return -NLE_MSGSIZE;
|
||||
}
|
||||
|
||||
static int send_log_request(struct nl_handle *handle, struct nl_msg *msg)
|
||||
static int send_log_request(struct nl_sock *sk, struct nl_msg *msg)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = nl_send_auto_complete(handle, msg);
|
||||
err = nl_send_auto_complete(sk, msg);
|
||||
nlmsg_free(msg);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
int nfnl_log_build_pf_bind(uint8_t pf, struct nl_msg **result)
|
||||
|
@ -71,7 +71,7 @@ int nfnl_log_build_pf_bind(uint8_t pf, struct nl_msg **result)
|
|||
return build_log_cmd_request(pf, 0, NFULNL_CFG_CMD_PF_BIND, result);
|
||||
}
|
||||
|
||||
int nfnl_log_pf_bind(struct nl_handle *nlh, uint8_t pf)
|
||||
int nfnl_log_pf_bind(struct nl_sock *nlh, uint8_t pf)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -87,7 +87,7 @@ int nfnl_log_build_pf_unbind(uint8_t pf, struct nl_msg **result)
|
|||
return build_log_cmd_request(pf, 0, NFULNL_CFG_CMD_PF_UNBIND, result);
|
||||
}
|
||||
|
||||
int nfnl_log_pf_unbind(struct nl_handle *nlh, uint8_t pf)
|
||||
int nfnl_log_pf_unbind(struct nl_sock *nlh, uint8_t pf)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -179,7 +179,7 @@ nla_put_failure:
|
|||
return -NLE_MSGSIZE;
|
||||
}
|
||||
|
||||
int nfnl_log_create(struct nl_handle *nlh, const struct nfnl_log *log)
|
||||
int nfnl_log_create(struct nl_sock *nlh, const struct nfnl_log *log)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -196,7 +196,7 @@ int nfnl_log_build_change_request(const struct nfnl_log *log,
|
|||
return nfnl_log_build_request(log, result);
|
||||
}
|
||||
|
||||
int nfnl_log_change(struct nl_handle *nlh, const struct nfnl_log *log)
|
||||
int nfnl_log_change(struct nl_sock *nlh, const struct nfnl_log *log)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -217,7 +217,7 @@ int nfnl_log_build_delete_request(const struct nfnl_log *log,
|
|||
NFULNL_CFG_CMD_UNBIND, result);
|
||||
}
|
||||
|
||||
int nfnl_log_delete(struct nl_handle *nlh, const struct nfnl_log *log)
|
||||
int nfnl_log_delete(struct nl_sock *nlh, const struct nfnl_log *log)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
* nla_put_u32(msg, 1, 0x10);
|
||||
*
|
||||
* // Message is ready to be sent.
|
||||
* nl_send_auto_complete(nl_handle, msg);
|
||||
* nl_send_auto_complete(sk, msg);
|
||||
*
|
||||
* // All done? Free the message.
|
||||
* nlmsg_free(msg);
|
||||
|
@ -57,7 +57,7 @@
|
|||
* @code
|
||||
* // For trivial messages not requiring any subsys specific header or
|
||||
* // attributes, nfnl_send_simple() may be used to send messages directly.
|
||||
* nfnl_send_simple(nl_handle, SUBSYS, TYPE, 0, FAMILY, RES_ID);
|
||||
* nfnl_send_simple(sk, SUBSYS, TYPE, 0, FAMILY, RES_ID);
|
||||
* @endcode
|
||||
* @{
|
||||
*/
|
||||
|
@ -73,7 +73,7 @@
|
|||
|
||||
/**
|
||||
* Create and connect netfilter netlink socket.
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
*
|
||||
* Creates a NETLINK_NETFILTER netlink socket, binds the socket and
|
||||
* issues a connection attempt.
|
||||
|
@ -82,9 +82,9 @@
|
|||
*
|
||||
* @return 0 on success or a negative error code.
|
||||
*/
|
||||
int nfnl_connect(struct nl_handle *handle)
|
||||
int nfnl_connect(struct nl_sock *sk)
|
||||
{
|
||||
return nl_connect(handle, NETLINK_NETFILTER);
|
||||
return nl_connect(sk, NETLINK_NETFILTER);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -96,7 +96,7 @@ int nfnl_connect(struct nl_handle *handle)
|
|||
|
||||
/**
|
||||
* Send trivial netfilter netlink message
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg subsys_id nfnetlink subsystem
|
||||
* @arg type nfnetlink message type
|
||||
* @arg flags message flags
|
||||
|
@ -105,7 +105,7 @@ int nfnl_connect(struct nl_handle *handle)
|
|||
*
|
||||
* @return Newly allocated netlink message or NULL.
|
||||
*/
|
||||
int nfnl_send_simple(struct nl_handle *handle, uint8_t subsys_id, uint8_t type,
|
||||
int nfnl_send_simple(struct nl_sock *sk, uint8_t subsys_id, uint8_t type,
|
||||
int flags, uint8_t family, uint16_t res_id)
|
||||
{
|
||||
struct nfgenmsg hdr = {
|
||||
|
@ -114,7 +114,7 @@ int nfnl_send_simple(struct nl_handle *handle, uint8_t subsys_id, uint8_t type,
|
|||
.res_id = htons(res_id),
|
||||
};
|
||||
|
||||
return nl_send_simple(handle, NFNLMSG_TYPE(subsys_id, type), flags,
|
||||
return nl_send_simple(sk, NFNLMSG_TYPE(subsys_id, type), flags,
|
||||
&hdr, sizeof(hdr));
|
||||
}
|
||||
|
||||
|
|
|
@ -24,16 +24,16 @@
|
|||
#include <netlink/netfilter/nfnl.h>
|
||||
#include <netlink/netfilter/queue.h>
|
||||
|
||||
static int send_queue_request(struct nl_handle *handle, struct nl_msg *msg)
|
||||
static int send_queue_request(struct nl_sock *sk, struct nl_msg *msg)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = nl_send_auto_complete(handle, msg);
|
||||
err = nl_send_auto_complete(sk, msg);
|
||||
nlmsg_free(msg);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,7 +71,7 @@ int nfnl_queue_build_pf_bind(uint8_t pf, struct nl_msg **result)
|
|||
return build_queue_cmd_request(pf, 0, NFQNL_CFG_CMD_PF_BIND, result);
|
||||
}
|
||||
|
||||
int nfnl_queue_pf_bind(struct nl_handle *nlh, uint8_t pf)
|
||||
int nfnl_queue_pf_bind(struct nl_sock *nlh, uint8_t pf)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -87,7 +87,7 @@ int nfnl_queue_build_pf_unbind(uint8_t pf, struct nl_msg **result)
|
|||
return build_queue_cmd_request(pf, 0, NFQNL_CFG_CMD_PF_UNBIND, result);
|
||||
}
|
||||
|
||||
int nfnl_queue_pf_unbind(struct nl_handle *nlh, uint8_t pf)
|
||||
int nfnl_queue_pf_unbind(struct nl_sock *nlh, uint8_t pf)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -169,7 +169,7 @@ nla_put_failure:
|
|||
return -NLE_MSGSIZE;
|
||||
}
|
||||
|
||||
int nfnl_queue_create(struct nl_handle *nlh, const struct nfnl_queue *queue)
|
||||
int nfnl_queue_create(struct nl_sock *nlh, const struct nfnl_queue *queue)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -186,7 +186,7 @@ int nfnl_queue_build_change_request(const struct nfnl_queue *queue,
|
|||
return nfnl_queue_build_request(queue, result);
|
||||
}
|
||||
|
||||
int nfnl_queue_change(struct nl_handle *nlh, const struct nfnl_queue *queue)
|
||||
int nfnl_queue_change(struct nl_sock *nlh, const struct nfnl_queue *queue)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -207,7 +207,7 @@ int nfnl_queue_build_delete_request(const struct nfnl_queue *queue,
|
|||
NFQNL_CFG_CMD_UNBIND, result);
|
||||
}
|
||||
|
||||
int nfnl_queue_delete(struct nl_handle *nlh, const struct nfnl_queue *queue)
|
||||
int nfnl_queue_delete(struct nl_sock *nlh, const struct nfnl_queue *queue)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
|
|
@ -194,7 +194,7 @@ nla_put_failure:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int nfnl_queue_msg_send_verdict(struct nl_handle *nlh,
|
||||
int nfnl_queue_msg_send_verdict(struct nl_sock *nlh,
|
||||
const struct nfnl_queue_msg *msg)
|
||||
{
|
||||
struct nl_msg *nlmsg;
|
||||
|
|
175
lib/nl.c
175
lib/nl.c
|
@ -101,7 +101,7 @@
|
|||
* @par 1) Connecting the socket
|
||||
* @code
|
||||
* // Bind and connect the socket to a protocol, NETLINK_ROUTE in this example.
|
||||
* nl_connect(handle, NETLINK_ROUTE);
|
||||
* nl_connect(sk, NETLINK_ROUTE);
|
||||
* @endcode
|
||||
*
|
||||
* @par 2) Sending data
|
||||
|
@ -110,29 +110,29 @@
|
|||
* // a piece of data to the other netlink peer. This method is not
|
||||
* // recommended.
|
||||
* const char buf[] = { 0x01, 0x02, 0x03, 0x04 };
|
||||
* nl_sendto(handle, buf, sizeof(buf));
|
||||
* nl_sendto(sk, buf, sizeof(buf));
|
||||
*
|
||||
* // A more comfortable interface is nl_send() taking a pointer to
|
||||
* // a netlink message.
|
||||
* struct nl_msg *msg = my_msg_builder();
|
||||
* nl_send(handle, nlmsg_hdr(msg));
|
||||
* nl_send(sk, nlmsg_hdr(msg));
|
||||
*
|
||||
* // nl_sendmsg() provides additional control over the sendmsg() message
|
||||
* // header in order to allow more specific addressing of multiple peers etc.
|
||||
* struct msghdr hdr = { ... };
|
||||
* nl_sendmsg(handle, nlmsg_hdr(msg), &hdr);
|
||||
* nl_sendmsg(sk, nlmsg_hdr(msg), &hdr);
|
||||
*
|
||||
* // You're probably too lazy to fill out the netlink pid, sequence number
|
||||
* // and message flags all the time. nl_send_auto_complete() automatically
|
||||
* // extends your message header as needed with an appropriate sequence
|
||||
* // number, the netlink pid stored in the netlink handle and the message
|
||||
* // number, the netlink pid stored in the netlink socket and the message
|
||||
* // flags NLM_F_REQUEST and NLM_F_ACK
|
||||
* nl_send_auto_complete(handle, nlmsg_hdr(msg));
|
||||
* nl_send_auto_complete(sk, nlmsg_hdr(msg));
|
||||
*
|
||||
* // Simple protocols don't require the complex message construction interface
|
||||
* // and may favour nl_send_simple() to easly send a bunch of payload
|
||||
* // encapsulated in a netlink message header.
|
||||
* nl_send_simple(handle, MY_MSG_TYPE, 0, buf, sizeof(buf));
|
||||
* nl_send_simple(sk, MY_MSG_TYPE, 0, buf, sizeof(buf));
|
||||
* @endcode
|
||||
*
|
||||
* @par 3) Receiving data
|
||||
|
@ -141,26 +141,26 @@
|
|||
* // content and gives back the pointer to you.
|
||||
* struct sockaddr_nl peer;
|
||||
* unsigned char *msg;
|
||||
* nl_recv(handle, &peer, &msg);
|
||||
* nl_recv(sk, &peer, &msg);
|
||||
*
|
||||
* // nl_recvmsgs() receives a bunch of messages until the callback system
|
||||
* // orders it to state, usually after receving a compolete multi part
|
||||
* // message series.
|
||||
* nl_recvmsgs(handle, my_callback_configuration);
|
||||
* nl_recvmsgs(sk, my_callback_configuration);
|
||||
*
|
||||
* // nl_recvmsgs_default() acts just like nl_recvmsg() but uses the callback
|
||||
* // configuration stored in the handle.
|
||||
* nl_recvmsgs_default(handle);
|
||||
* // configuration stored in the socket.
|
||||
* nl_recvmsgs_default(sk);
|
||||
*
|
||||
* // In case you want to wait for the ACK to be recieved that you requested
|
||||
* // with your latest message, you can call nl_wait_for_ack()
|
||||
* nl_wait_for_ack(handle);
|
||||
* nl_wait_for_ack(sk);
|
||||
* @endcode
|
||||
*
|
||||
* @par 4) Closing
|
||||
* @code
|
||||
* // Close the socket first to release kernel memory
|
||||
* nl_close(handle);
|
||||
* nl_close(sk);
|
||||
* @endcode
|
||||
*
|
||||
* @{
|
||||
|
@ -180,7 +180,7 @@
|
|||
|
||||
/**
|
||||
* Create and connect netlink socket.
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg protocol Netlink protocol to use.
|
||||
*
|
||||
* Creates a netlink socket using the specified protocol, binds the socket
|
||||
|
@ -188,70 +188,70 @@
|
|||
*
|
||||
* @return 0 on success or a negative error code.
|
||||
*/
|
||||
int nl_connect(struct nl_handle *handle, int protocol)
|
||||
int nl_connect(struct nl_sock *sk, int protocol)
|
||||
{
|
||||
int err;
|
||||
socklen_t addrlen;
|
||||
|
||||
handle->h_fd = socket(AF_NETLINK, SOCK_RAW, protocol);
|
||||
if (handle->h_fd < 0) {
|
||||
sk->s_fd = socket(AF_NETLINK, SOCK_RAW, protocol);
|
||||
if (sk->s_fd < 0) {
|
||||
err = -nl_syserr2nlerr(errno);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (!(handle->h_flags & NL_SOCK_BUFSIZE_SET)) {
|
||||
err = nl_set_buffer_size(handle, 0, 0);
|
||||
if (!(sk->s_flags & NL_SOCK_BUFSIZE_SET)) {
|
||||
err = nl_set_buffer_size(sk, 0, 0);
|
||||
if (err < 0)
|
||||
goto errout;
|
||||
}
|
||||
|
||||
err = bind(handle->h_fd, (struct sockaddr*) &handle->h_local,
|
||||
sizeof(handle->h_local));
|
||||
err = bind(sk->s_fd, (struct sockaddr*) &sk->s_local,
|
||||
sizeof(sk->s_local));
|
||||
if (err < 0) {
|
||||
err = -nl_syserr2nlerr(errno);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
addrlen = sizeof(handle->h_local);
|
||||
err = getsockname(handle->h_fd, (struct sockaddr *) &handle->h_local,
|
||||
addrlen = sizeof(sk->s_local);
|
||||
err = getsockname(sk->s_fd, (struct sockaddr *) &sk->s_local,
|
||||
&addrlen);
|
||||
if (err < 0) {
|
||||
err = -nl_syserr2nlerr(errno);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (addrlen != sizeof(handle->h_local)) {
|
||||
if (addrlen != sizeof(sk->s_local)) {
|
||||
err = -NLE_NOADDR;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (handle->h_local.nl_family != AF_NETLINK) {
|
||||
if (sk->s_local.nl_family != AF_NETLINK) {
|
||||
err = -NLE_AF_NOSUPPORT;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
handle->h_proto = protocol;
|
||||
sk->s_proto = protocol;
|
||||
|
||||
return 0;
|
||||
errout:
|
||||
close(handle->h_fd);
|
||||
handle->h_fd = -1;
|
||||
close(sk->s_fd);
|
||||
sk->s_fd = -1;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close/Disconnect netlink socket.
|
||||
* @arg handle Netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
*/
|
||||
void nl_close(struct nl_handle *handle)
|
||||
void nl_close(struct nl_sock *sk)
|
||||
{
|
||||
if (handle->h_fd >= 0) {
|
||||
close(handle->h_fd);
|
||||
handle->h_fd = -1;
|
||||
if (sk->s_fd >= 0) {
|
||||
close(sk->s_fd);
|
||||
sk->s_fd = -1;
|
||||
}
|
||||
|
||||
handle->h_proto = 0;
|
||||
sk->s_proto = 0;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -263,17 +263,17 @@ void nl_close(struct nl_handle *handle)
|
|||
|
||||
/**
|
||||
* Send raw data over netlink socket.
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg buf Data buffer.
|
||||
* @arg size Size of data buffer.
|
||||
* @return Number of characters written on success or a negative error code.
|
||||
*/
|
||||
int nl_sendto(struct nl_handle *handle, void *buf, size_t size)
|
||||
int nl_sendto(struct nl_sock *sk, void *buf, size_t size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = sendto(handle->h_fd, buf, size, 0, (struct sockaddr *)
|
||||
&handle->h_peer, sizeof(handle->h_peer));
|
||||
ret = sendto(sk->s_fd, buf, size, 0, (struct sockaddr *)
|
||||
&sk->s_peer, sizeof(sk->s_peer));
|
||||
if (ret < 0)
|
||||
return -nl_syserr2nlerr(errno);
|
||||
|
||||
|
@ -282,12 +282,12 @@ int nl_sendto(struct nl_handle *handle, void *buf, size_t size)
|
|||
|
||||
/**
|
||||
* Send netlink message with control over sendmsg() message header.
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg msg Netlink message to be sent.
|
||||
* @arg hdr Sendmsg() message header.
|
||||
* @return Number of characters sent on sucess or a negative error code.
|
||||
*/
|
||||
int nl_sendmsg(struct nl_handle *handle, struct nl_msg *msg, struct msghdr *hdr)
|
||||
int nl_sendmsg(struct nl_sock *sk, struct nl_msg *msg, struct msghdr *hdr)
|
||||
{
|
||||
struct nl_cb *cb;
|
||||
int ret;
|
||||
|
@ -300,14 +300,14 @@ int nl_sendmsg(struct nl_handle *handle, struct nl_msg *msg, struct msghdr *hdr)
|
|||
hdr->msg_iov = &iov;
|
||||
hdr->msg_iovlen = 1;
|
||||
|
||||
nlmsg_set_src(msg, &handle->h_local);
|
||||
nlmsg_set_src(msg, &sk->s_local);
|
||||
|
||||
cb = handle->h_cb;
|
||||
cb = sk->s_cb;
|
||||
if (cb->cb_set[NL_CB_MSG_OUT])
|
||||
if (nl_cb_call(cb, NL_CB_MSG_OUT, msg) != NL_OK)
|
||||
return 0;
|
||||
|
||||
ret = sendmsg(handle->h_fd, hdr, 0);
|
||||
ret = sendmsg(sk->s_fd, hdr, 0);
|
||||
if (ret < 0)
|
||||
return -nl_syserr2nlerr(errno);
|
||||
|
||||
|
@ -317,23 +317,23 @@ int nl_sendmsg(struct nl_handle *handle, struct nl_msg *msg, struct msghdr *hdr)
|
|||
|
||||
/**
|
||||
* Send netlink message.
|
||||
* @arg handle Netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg msg Netlink message to be sent.
|
||||
* @see nl_sendmsg()
|
||||
* @return Number of characters sent on success or a negative error code.
|
||||
*/
|
||||
int nl_send(struct nl_handle *handle, struct nl_msg *msg)
|
||||
int nl_send(struct nl_sock *sk, struct nl_msg *msg)
|
||||
{
|
||||
struct sockaddr_nl *dst;
|
||||
struct ucred *creds;
|
||||
|
||||
struct msghdr hdr = {
|
||||
.msg_name = (void *) &handle->h_peer,
|
||||
.msg_name = (void *) &sk->s_peer,
|
||||
.msg_namelen = sizeof(struct sockaddr_nl),
|
||||
};
|
||||
|
||||
/* Overwrite destination if specified in the message itself, defaults
|
||||
* to the peer address of the handle.
|
||||
* to the peer address of the socket.
|
||||
*/
|
||||
dst = nlmsg_get_dst(msg);
|
||||
if (dst->nl_family == AF_NETLINK)
|
||||
|
@ -355,12 +355,12 @@ int nl_send(struct nl_handle *handle, struct nl_msg *msg)
|
|||
memcpy(CMSG_DATA(cmsg), creds, sizeof(struct ucred));
|
||||
}
|
||||
|
||||
return nl_sendmsg(handle, msg, &hdr);
|
||||
return nl_sendmsg(sk, msg, &hdr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send netlink message and check & extend header values as needed.
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg msg Netlink message to be sent.
|
||||
*
|
||||
* Checks the netlink message \c nlh for completness and extends it
|
||||
|
@ -370,32 +370,32 @@ int nl_send(struct nl_handle *handle, struct nl_msg *msg)
|
|||
* @see nl_send()
|
||||
* @return Number of characters sent or a negative error code.
|
||||
*/
|
||||
int nl_send_auto_complete(struct nl_handle *handle, struct nl_msg *msg)
|
||||
int nl_send_auto_complete(struct nl_sock *sk, struct nl_msg *msg)
|
||||
{
|
||||
struct nlmsghdr *nlh;
|
||||
struct nl_cb *cb = handle->h_cb;
|
||||
struct nl_cb *cb = sk->s_cb;
|
||||
|
||||
nlh = nlmsg_hdr(msg);
|
||||
if (nlh->nlmsg_pid == 0)
|
||||
nlh->nlmsg_pid = handle->h_local.nl_pid;
|
||||
nlh->nlmsg_pid = sk->s_local.nl_pid;
|
||||
|
||||
if (nlh->nlmsg_seq == 0)
|
||||
nlh->nlmsg_seq = handle->h_seq_next++;
|
||||
nlh->nlmsg_seq = sk->s_seq_next++;
|
||||
|
||||
if (msg->nm_protocol == -1)
|
||||
msg->nm_protocol = handle->h_proto;
|
||||
msg->nm_protocol = sk->s_proto;
|
||||
|
||||
nlh->nlmsg_flags |= (NLM_F_REQUEST | NLM_F_ACK);
|
||||
|
||||
if (cb->cb_send_ow)
|
||||
return cb->cb_send_ow(handle, msg);
|
||||
return cb->cb_send_ow(sk, msg);
|
||||
else
|
||||
return nl_send(handle, msg);
|
||||
return nl_send(sk, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send simple netlink message using nl_send_auto_complete()
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg type Netlink message type.
|
||||
* @arg flags Netlink message flags.
|
||||
* @arg buf Data buffer.
|
||||
|
@ -407,7 +407,7 @@ int nl_send_auto_complete(struct nl_handle *handle, struct nl_msg *msg)
|
|||
* @see nl_send_auto_complete()
|
||||
* @return Number of characters sent on success or a negative error code.
|
||||
*/
|
||||
int nl_send_simple(struct nl_handle *handle, int type, int flags, void *buf,
|
||||
int nl_send_simple(struct nl_sock *sk, int type, int flags, void *buf,
|
||||
size_t size)
|
||||
{
|
||||
int err;
|
||||
|
@ -424,7 +424,7 @@ int nl_send_simple(struct nl_handle *handle, int type, int flags, void *buf,
|
|||
}
|
||||
|
||||
|
||||
err = nl_send_auto_complete(handle, msg);
|
||||
err = nl_send_auto_complete(sk, msg);
|
||||
errout:
|
||||
nlmsg_free(msg);
|
||||
|
||||
|
@ -440,7 +440,7 @@ errout:
|
|||
|
||||
/**
|
||||
* Receive data from netlink socket
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg nla Destination pointer for peer's netlink address.
|
||||
* @arg buf Destination pointer for message content.
|
||||
* @arg creds Destination pointer for credentials.
|
||||
|
@ -457,7 +457,7 @@ errout:
|
|||
*
|
||||
* @return Number of octets read, 0 on EOF or a negative error code.
|
||||
*/
|
||||
int nl_recv(struct nl_handle *handle, struct sockaddr_nl *nla,
|
||||
int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla,
|
||||
unsigned char **buf, struct ucred **creds)
|
||||
{
|
||||
int n;
|
||||
|
@ -475,7 +475,7 @@ int nl_recv(struct nl_handle *handle, struct sockaddr_nl *nla,
|
|||
};
|
||||
struct cmsghdr *cmsg;
|
||||
|
||||
if (handle->h_flags & NL_MSG_PEEK)
|
||||
if (sk->s_flags & NL_MSG_PEEK)
|
||||
flags |= MSG_PEEK;
|
||||
|
||||
if (page_size == 0)
|
||||
|
@ -484,13 +484,13 @@ int nl_recv(struct nl_handle *handle, struct sockaddr_nl *nla,
|
|||
iov.iov_len = page_size;
|
||||
iov.iov_base = *buf = malloc(iov.iov_len);
|
||||
|
||||
if (handle->h_flags & NL_SOCK_PASSCRED) {
|
||||
if (sk->s_flags & NL_SOCK_PASSCRED) {
|
||||
msg.msg_controllen = CMSG_SPACE(sizeof(struct ucred));
|
||||
msg.msg_control = calloc(1, msg.msg_controllen);
|
||||
}
|
||||
retry:
|
||||
|
||||
n = recvmsg(handle->h_fd, &msg, flags);
|
||||
n = recvmsg(sk->s_fd, &msg, flags);
|
||||
if (!n)
|
||||
goto abort;
|
||||
else if (n < 0) {
|
||||
|
@ -580,7 +580,7 @@ do { \
|
|||
* it freed and cause a race condition with later access to that (now
|
||||
* freed) data.
|
||||
*/
|
||||
static int recvmsgs(struct nl_handle *handle, struct nl_cb *cb)
|
||||
static int recvmsgs(struct nl_sock *sk, struct nl_cb *cb)
|
||||
{
|
||||
int n, err = 0, multipart = 0;
|
||||
unsigned char *buf = NULL, free_msg = 1;
|
||||
|
@ -590,21 +590,20 @@ static int recvmsgs(struct nl_handle *handle, struct nl_cb *cb)
|
|||
struct ucred *creds = NULL;
|
||||
|
||||
continue_reading:
|
||||
NL_DBG(3, "Attempting to read from %p\n", handle);
|
||||
NL_DBG(3, "Attempting to read from %p\n", sk);
|
||||
if (cb->cb_recv_ow)
|
||||
n = cb->cb_recv_ow(handle, &nla, &buf, &creds);
|
||||
n = cb->cb_recv_ow(sk, &nla, &buf, &creds);
|
||||
else
|
||||
n = nl_recv(handle, &nla, &buf, &creds);
|
||||
n = nl_recv(sk, &nla, &buf, &creds);
|
||||
|
||||
if (n <= 0)
|
||||
return n;
|
||||
|
||||
NL_DBG(3, "recvmsgs(%p): Read %d bytes\n", handle, n);
|
||||
NL_DBG(3, "recvmsgs(%p): Read %d bytes\n", sk, n);
|
||||
|
||||
hdr = (struct nlmsghdr *) buf;
|
||||
while (nlmsg_ok(hdr, n)) {
|
||||
NL_DBG(3, "recgmsgs(%p): Processing valid message...\n",
|
||||
handle);
|
||||
NL_DBG(3, "recgmsgs(%p): Processing valid message...\n", sk);
|
||||
|
||||
if (free_msg)
|
||||
nlmsg_free(msg);
|
||||
|
@ -615,7 +614,7 @@ continue_reading:
|
|||
goto out;
|
||||
}
|
||||
|
||||
nlmsg_set_proto(msg, handle->h_proto);
|
||||
nlmsg_set_proto(msg, sk->s_proto);
|
||||
nlmsg_set_src(msg, &nla);
|
||||
if (creds)
|
||||
nlmsg_set_creds(msg, creds);
|
||||
|
@ -630,7 +629,7 @@ continue_reading:
|
|||
* enforcing strict ordering */
|
||||
if (cb->cb_set[NL_CB_SEQ_CHECK])
|
||||
NL_CB_CALL(cb, NL_CB_SEQ_CHECK, msg);
|
||||
else if (hdr->nlmsg_seq != handle->h_seq_expect) {
|
||||
else if (hdr->nlmsg_seq != sk->s_seq_expect) {
|
||||
if (cb->cb_set[NL_CB_INVALID])
|
||||
NL_CB_CALL(cb, NL_CB_INVALID, msg);
|
||||
else {
|
||||
|
@ -645,10 +644,10 @@ continue_reading:
|
|||
hdr->nlmsg_type == NLMSG_OVERRUN) {
|
||||
/* We can't check for !NLM_F_MULTI since some netlink
|
||||
* users in the kernel are broken. */
|
||||
handle->h_seq_expect++;
|
||||
sk->s_seq_expect++;
|
||||
NL_DBG(3, "recvmsgs(%p): Increased expected " \
|
||||
"sequence number to %d\n",
|
||||
handle, handle->h_seq_expect);
|
||||
sk, sk->s_seq_expect);
|
||||
}
|
||||
|
||||
if (hdr->nlmsg_flags & NLM_F_MULTI)
|
||||
|
@ -766,7 +765,7 @@ out:
|
|||
|
||||
/**
|
||||
* Receive a set of messages from a netlink socket.
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg cb set of callbacks to control behaviour.
|
||||
*
|
||||
* Repeatedly calls nl_recv() or the respective replacement if provided
|
||||
|
@ -779,23 +778,23 @@ out:
|
|||
*
|
||||
* @return 0 on success or a negative error code from nl_recv().
|
||||
*/
|
||||
int nl_recvmsgs(struct nl_handle *handle, struct nl_cb *cb)
|
||||
int nl_recvmsgs(struct nl_sock *sk, struct nl_cb *cb)
|
||||
{
|
||||
if (cb->cb_recvmsgs_ow)
|
||||
return cb->cb_recvmsgs_ow(handle, cb);
|
||||
return cb->cb_recvmsgs_ow(sk, cb);
|
||||
else
|
||||
return recvmsgs(handle, cb);
|
||||
return recvmsgs(sk, cb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive a set of message from a netlink socket using handlers in nl_handle.
|
||||
* @arg handle netlink handle
|
||||
* Receive a set of message from a netlink socket using handlers in nl_sock.
|
||||
* @arg sk Netlink socket.
|
||||
*
|
||||
* Calls nl_recvmsgs() with the handlers configured in the netlink handle.
|
||||
* Calls nl_recvmsgs() with the handlers configured in the netlink socket.
|
||||
*/
|
||||
int nl_recvmsgs_default(struct nl_handle *handle)
|
||||
int nl_recvmsgs_default(struct nl_sock *sk)
|
||||
{
|
||||
return nl_recvmsgs(handle, handle->h_cb);
|
||||
return nl_recvmsgs(sk, sk->s_cb);
|
||||
|
||||
}
|
||||
|
||||
|
@ -806,23 +805,23 @@ static int ack_wait_handler(struct nl_msg *msg, void *arg)
|
|||
|
||||
/**
|
||||
* Wait for ACK.
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @pre The netlink socket must be in blocking state.
|
||||
*
|
||||
* Waits until an ACK is received for the latest not yet acknowledged
|
||||
* netlink message.
|
||||
*/
|
||||
int nl_wait_for_ack(struct nl_handle *handle)
|
||||
int nl_wait_for_ack(struct nl_sock *sk)
|
||||
{
|
||||
int err;
|
||||
struct nl_cb *cb;
|
||||
|
||||
cb = nl_cb_clone(handle->h_cb);
|
||||
cb = nl_cb_clone(sk->s_cb);
|
||||
if (cb == NULL)
|
||||
return -NLE_NOMEM;
|
||||
|
||||
nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_wait_handler, NULL);
|
||||
err = nl_recvmsgs(handle, cb);
|
||||
err = nl_recvmsgs(sk, cb);
|
||||
nl_cb_put(cb);
|
||||
|
||||
return err;
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
* // block until the operation has been completed. Alternatively the required
|
||||
* // netlink message can be built using rtnl_addr_build_add_request() to be
|
||||
* // sent out using nl_send_auto_complete().
|
||||
* rtnl_addr_add(handle, addr, 0);
|
||||
* rtnl_addr_add(sk, addr, 0);
|
||||
*
|
||||
* // Free the memory
|
||||
* rtnl_addr_put(addr);
|
||||
|
@ -99,7 +99,7 @@
|
|||
* // block until the operation has been completed. Alternatively the required
|
||||
* // netlink message can be built using rtnl_addr_build_delete_request()
|
||||
* // to be sent out using nl_send_auto_complete().
|
||||
* rtnl_addr_delete(handle, addr, 0);
|
||||
* rtnl_addr_delete(sk, addr, 0);
|
||||
*
|
||||
* // Free the memory
|
||||
* rtnl_addr_put(addr);
|
||||
|
@ -297,9 +297,9 @@ errout_nomem:
|
|||
goto errout;
|
||||
}
|
||||
|
||||
static int addr_request_update(struct nl_cache *cache, struct nl_handle *handle)
|
||||
static int addr_request_update(struct nl_cache *cache, struct nl_sock *sk)
|
||||
{
|
||||
return nl_rtgen_request(handle, RTM_GETADDR, AF_UNSPEC, NLM_F_DUMP);
|
||||
return nl_rtgen_request(sk, RTM_GETADDR, AF_UNSPEC, NLM_F_DUMP);
|
||||
}
|
||||
|
||||
static int addr_dump_brief(struct nl_object *obj, struct nl_dump_params *p)
|
||||
|
@ -640,9 +640,9 @@ void rtnl_addr_put(struct rtnl_addr *addr)
|
|||
* @{
|
||||
*/
|
||||
|
||||
int rtnl_addr_alloc_cache(struct nl_handle *sock, struct nl_cache **result)
|
||||
int rtnl_addr_alloc_cache(struct nl_sock *sk, struct nl_cache **result)
|
||||
{
|
||||
return nl_cache_alloc_and_fill(&rtnl_addr_ops, sock, result);
|
||||
return nl_cache_alloc_and_fill(&rtnl_addr_ops, sk, result);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -742,7 +742,7 @@ int rtnl_addr_build_add_request(struct rtnl_addr *addr, int flags,
|
|||
|
||||
/**
|
||||
* Request addition of new address
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg addr Address object representing the new address.
|
||||
* @arg flags Additional netlink message flags.
|
||||
*
|
||||
|
@ -754,7 +754,7 @@ int rtnl_addr_build_add_request(struct rtnl_addr *addr, int flags,
|
|||
*
|
||||
* @return 0 on sucess or a negative error if an error occured.
|
||||
*/
|
||||
int rtnl_addr_add(struct nl_handle *handle, struct rtnl_addr *addr, int flags)
|
||||
int rtnl_addr_add(struct nl_sock *sk, struct rtnl_addr *addr, int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -762,12 +762,12 @@ int rtnl_addr_add(struct nl_handle *handle, struct rtnl_addr *addr, int flags)
|
|||
if ((err = rtnl_addr_build_add_request(addr, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
err = nl_send_auto_complete(handle, msg);
|
||||
err = nl_send_auto_complete(sk, msg);
|
||||
nlmsg_free(msg);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -814,7 +814,7 @@ int rtnl_addr_build_delete_request(struct rtnl_addr *addr, int flags,
|
|||
|
||||
/**
|
||||
* Request deletion of an address
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg addr Address object to be deleted.
|
||||
* @arg flags Additional netlink message flags.
|
||||
*
|
||||
|
@ -826,8 +826,7 @@ int rtnl_addr_build_delete_request(struct rtnl_addr *addr, int flags,
|
|||
*
|
||||
* @return 0 on sucess or a negative error if an error occured.
|
||||
*/
|
||||
int rtnl_addr_delete(struct nl_handle *handle, struct rtnl_addr *addr,
|
||||
int flags)
|
||||
int rtnl_addr_delete(struct nl_sock *sk, struct rtnl_addr *addr, int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -835,12 +834,12 @@ int rtnl_addr_delete(struct nl_handle *handle, struct rtnl_addr *addr,
|
|||
if ((err = rtnl_addr_build_delete_request(addr, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
err = nl_send_auto_complete(handle, msg);
|
||||
err = nl_send_auto_complete(sk, msg);
|
||||
nlmsg_free(msg);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -64,15 +64,14 @@ errout:
|
|||
return err;
|
||||
}
|
||||
|
||||
static int class_request_update(struct nl_cache *cache,
|
||||
struct nl_handle *handle)
|
||||
static int class_request_update(struct nl_cache *cache, struct nl_sock *sk)
|
||||
{
|
||||
struct tcmsg tchdr = {
|
||||
.tcm_family = AF_UNSPEC,
|
||||
.tcm_ifindex = cache->c_iarg1,
|
||||
};
|
||||
|
||||
return nl_send_simple(handle, RTM_GETTCLASS, NLM_F_DUMP, &tchdr,
|
||||
return nl_send_simple(sk, RTM_GETTCLASS, NLM_F_DUMP, &tchdr,
|
||||
sizeof(tchdr));
|
||||
}
|
||||
|
||||
|
@ -134,7 +133,7 @@ int rtnl_class_build_add_request(struct rtnl_class *class, int flags,
|
|||
|
||||
/**
|
||||
* Add a new class
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg class class to delete
|
||||
* @arg flags additional netlink message flags
|
||||
*
|
||||
|
@ -147,8 +146,7 @@ int rtnl_class_build_add_request(struct rtnl_class *class, int flags,
|
|||
*
|
||||
* @return 0 on success or a negative error code
|
||||
*/
|
||||
int rtnl_class_add(struct nl_handle *handle, struct rtnl_class *class,
|
||||
int flags)
|
||||
int rtnl_class_add(struct nl_sock *sk, struct rtnl_class *class, int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -156,11 +154,11 @@ int rtnl_class_add(struct nl_handle *handle, struct rtnl_class *class,
|
|||
if ((err = rtnl_class_build_add_request(class, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
if ((err = nl_send_auto_complete(handle, msg)) < 0)
|
||||
if ((err = nl_send_auto_complete(sk, msg)) < 0)
|
||||
return err;
|
||||
|
||||
nlmsg_free(msg);
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -172,7 +170,7 @@ int rtnl_class_add(struct nl_handle *handle, struct rtnl_class *class,
|
|||
|
||||
/**
|
||||
* Build a class cache including all classes attached to the specified interface
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg ifindex interface index of the link the classes are
|
||||
* attached to.
|
||||
*
|
||||
|
@ -181,7 +179,7 @@ int rtnl_class_add(struct nl_handle *handle, struct rtnl_class *class,
|
|||
*
|
||||
* @return The cache or NULL if an error has occured.
|
||||
*/
|
||||
int rtnl_class_alloc_cache(struct nl_handle *handle, int ifindex,
|
||||
int rtnl_class_alloc_cache(struct nl_sock *sk, int ifindex,
|
||||
struct nl_cache **result)
|
||||
{
|
||||
struct nl_cache * cache;
|
||||
|
@ -193,7 +191,7 @@ int rtnl_class_alloc_cache(struct nl_handle *handle, int ifindex,
|
|||
|
||||
cache->c_iarg1 = ifindex;
|
||||
|
||||
if (handle && (err = nl_cache_refill(handle, cache)) < 0) {
|
||||
if (sk && (err = nl_cache_refill(sk, cache)) < 0) {
|
||||
nl_cache_free(cache);
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ errout:
|
|||
return err;
|
||||
}
|
||||
|
||||
static int cls_request_update(struct nl_cache *cache, struct nl_handle *handle)
|
||||
static int cls_request_update(struct nl_cache *cache, struct nl_sock *sk)
|
||||
{
|
||||
struct tcmsg tchdr = {
|
||||
.tcm_family = AF_UNSPEC,
|
||||
|
@ -83,7 +83,7 @@ static int cls_request_update(struct nl_cache *cache, struct nl_handle *handle)
|
|||
.tcm_parent = cache->c_iarg2,
|
||||
};
|
||||
|
||||
return nl_send_simple(handle, RTM_GETTFILTER, NLM_F_DUMP, &tchdr,
|
||||
return nl_send_simple(sk, RTM_GETTFILTER, NLM_F_DUMP, &tchdr,
|
||||
sizeof(tchdr));
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ int rtnl_cls_build_add_request(struct rtnl_cls *cls, int flags,
|
|||
|
||||
/**
|
||||
* Add a new classifier
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg cls classifier to add
|
||||
* @arg flags additional netlink message flags
|
||||
*
|
||||
|
@ -161,7 +161,7 @@ int rtnl_cls_build_add_request(struct rtnl_cls *cls, int flags,
|
|||
*
|
||||
* @return 0 on sucess or a negative error if an error occured.
|
||||
*/
|
||||
int rtnl_cls_add(struct nl_handle *handle, struct rtnl_cls *cls, int flags)
|
||||
int rtnl_cls_add(struct nl_sock *sk, struct rtnl_cls *cls, int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -169,11 +169,11 @@ int rtnl_cls_add(struct nl_handle *handle, struct rtnl_cls *cls, int flags)
|
|||
if ((err = rtnl_cls_build_add_request(cls, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
if ((err = nl_send_auto_complete(handle, msg)) < 0)
|
||||
if ((err = nl_send_auto_complete(sk, msg)) < 0)
|
||||
return err;
|
||||
|
||||
nlmsg_free(msg);
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,7 +197,7 @@ int rtnl_cls_build_change_request(struct rtnl_cls *cls, int flags,
|
|||
|
||||
/**
|
||||
* Change a classifier
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg cls classifier to change
|
||||
* @arg flags additional netlink message flags
|
||||
*
|
||||
|
@ -207,8 +207,7 @@ int rtnl_cls_build_change_request(struct rtnl_cls *cls, int flags,
|
|||
*
|
||||
* @return 0 on sucess or a negative error if an error occured.
|
||||
*/
|
||||
int rtnl_cls_change(struct nl_handle *handle, struct rtnl_cls *cls,
|
||||
int flags)
|
||||
int rtnl_cls_change(struct nl_sock *sk, struct rtnl_cls *cls, int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -216,11 +215,11 @@ int rtnl_cls_change(struct nl_handle *handle, struct rtnl_cls *cls,
|
|||
if ((err = rtnl_cls_build_change_request(cls, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
if ((err = nl_send_auto_complete(handle, msg)) < 0)
|
||||
if ((err = nl_send_auto_complete(sk, msg)) < 0)
|
||||
return err;
|
||||
|
||||
nlmsg_free(msg);
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,7 +244,7 @@ int rtnl_cls_build_delete_request(struct rtnl_cls *cls, int flags,
|
|||
|
||||
/**
|
||||
* Delete a classifier
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg cls classifier to delete
|
||||
* @arg flags additional netlink message flags
|
||||
*
|
||||
|
@ -255,7 +254,7 @@ int rtnl_cls_build_delete_request(struct rtnl_cls *cls, int flags,
|
|||
*
|
||||
* @return 0 on sucess or a negative error if an error occured.
|
||||
*/
|
||||
int rtnl_cls_delete(struct nl_handle *handle, struct rtnl_cls *cls, int flags)
|
||||
int rtnl_cls_delete(struct nl_sock *sk, struct rtnl_cls *cls, int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -263,11 +262,11 @@ int rtnl_cls_delete(struct nl_handle *handle, struct rtnl_cls *cls, int flags)
|
|||
if ((err = rtnl_cls_build_delete_request(cls, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
if ((err = nl_send_auto_complete(handle, msg)) < 0)
|
||||
if ((err = nl_send_auto_complete(sk, msg)) < 0)
|
||||
return err;
|
||||
|
||||
nlmsg_free(msg);
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -280,7 +279,7 @@ int rtnl_cls_delete(struct nl_handle *handle, struct rtnl_cls *cls, int flags)
|
|||
/**
|
||||
* Build a classifier cache including all classifiers attached to the
|
||||
* specified class/qdisc on eht specified interface.
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg ifindex interface index of the link the classes are
|
||||
* attached to.
|
||||
* @arg parent parent qdisc/class
|
||||
|
@ -293,7 +292,7 @@ int rtnl_cls_delete(struct nl_handle *handle, struct rtnl_cls *cls, int flags)
|
|||
* cache after using it.
|
||||
* @return 0 on success or a negative error code.
|
||||
*/
|
||||
int rtnl_cls_alloc_cache(struct nl_handle *handle, int ifindex, uint32_t parent, struct nl_cache **result)
|
||||
int rtnl_cls_alloc_cache(struct nl_sock *sk, int ifindex, uint32_t parent, struct nl_cache **result)
|
||||
{
|
||||
struct nl_cache * cache;
|
||||
int err;
|
||||
|
@ -304,7 +303,7 @@ int rtnl_cls_alloc_cache(struct nl_handle *handle, int ifindex, uint32_t parent,
|
|||
cache->c_iarg1 = ifindex;
|
||||
cache->c_iarg2 = parent;
|
||||
|
||||
if (handle && (err = nl_cache_refill(handle, cache)) < 0) {
|
||||
if (sk && (err = nl_cache_refill(sk, cache)) < 0) {
|
||||
nl_cache_free(cache);
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
* @code
|
||||
* // The first step is to retrieve a list of all available interfaces within
|
||||
* // the kernel and put them into a cache.
|
||||
* struct nl_cache *cache = rtnl_link_alloc_cache(nl_handle);
|
||||
* struct nl_cache *cache = rtnl_link_alloc_cache(sk);
|
||||
*
|
||||
* // In a second step, a specific link may be looked up by either interface
|
||||
* // index or interface name.
|
||||
|
@ -112,12 +112,12 @@
|
|||
* // Two ways exist to commit this change request, the first one is to
|
||||
* // build the required netlink message and send it out in one single
|
||||
* // step:
|
||||
* rtnl_link_change(nl_handle, old, request);
|
||||
* rtnl_link_change(sk, old, request);
|
||||
*
|
||||
* // An alternative way is to build the netlink message and send it
|
||||
* // out yourself using nl_send_auto_complete()
|
||||
* struct nl_msg *msg = rtnl_link_build_change_request(old, request);
|
||||
* nl_send_auto_complete(nl_handle, nlmsg_hdr(msg));
|
||||
* nl_send_auto_complete(sk, nlmsg_hdr(msg));
|
||||
* nlmsg_free(msg);
|
||||
*
|
||||
* // Don't forget to give back the link object ;->
|
||||
|
@ -427,9 +427,9 @@ errout:
|
|||
return err;
|
||||
}
|
||||
|
||||
static int link_request_update(struct nl_cache *c, struct nl_handle *h)
|
||||
static int link_request_update(struct nl_cache *cache, struct nl_sock *sk)
|
||||
{
|
||||
return nl_rtgen_request(h, RTM_GETLINK, AF_UNSPEC, NLM_F_DUMP);
|
||||
return nl_rtgen_request(sk, RTM_GETLINK, AF_UNSPEC, NLM_F_DUMP);
|
||||
}
|
||||
|
||||
static int link_dump_brief(struct nl_object *obj, struct nl_dump_params *p)
|
||||
|
@ -861,7 +861,7 @@ void rtnl_link_put(struct rtnl_link *link)
|
|||
|
||||
/**
|
||||
* Allocate link cache and fill in all configured links.
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg result Pointer to store resulting cache.
|
||||
*
|
||||
* Allocates a new link cache, initializes it properly and updates it
|
||||
|
@ -869,9 +869,9 @@ void rtnl_link_put(struct rtnl_link *link)
|
|||
*
|
||||
* @return 0 on success or a negative error code.
|
||||
*/
|
||||
int rtnl_link_alloc_cache(struct nl_handle *sock, struct nl_cache **result)
|
||||
int rtnl_link_alloc_cache(struct nl_sock *sk, struct nl_cache **result)
|
||||
{
|
||||
return nl_cache_alloc_and_fill(&rtnl_link_ops, sock, result);
|
||||
return nl_cache_alloc_and_fill(&rtnl_link_ops, sk, result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1025,7 +1025,7 @@ nla_put_failure:
|
|||
|
||||
/**
|
||||
* Change link attributes
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg old link to be changed
|
||||
* @arg tmpl template with requested changes
|
||||
* @arg flags additional netlink message flags
|
||||
|
@ -1038,7 +1038,7 @@ nla_put_failure:
|
|||
* @note Not all attributes can be changed, see
|
||||
* \ref link_changeable "Changeable Attributes" for more details.
|
||||
*/
|
||||
int rtnl_link_change(struct nl_handle *handle, struct rtnl_link *old,
|
||||
int rtnl_link_change(struct nl_sock *sk, struct rtnl_link *old,
|
||||
struct rtnl_link *tmpl, int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
|
@ -1047,11 +1047,11 @@ int rtnl_link_change(struct nl_handle *handle, struct rtnl_link *old,
|
|||
if ((err = rtnl_link_build_change_request(old, tmpl, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
if ((err = nl_send_auto_complete(handle, msg)) < 0)
|
||||
if ((err = nl_send_auto_complete(sk, msg)) < 0)
|
||||
return err;
|
||||
|
||||
nlmsg_free(msg);
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
* @code
|
||||
* // The first step is to retrieve a list of all available neighbour within
|
||||
* // the kernel and put them into a cache.
|
||||
* struct nl_cache *cache = rtnl_neigh_alloc_cache(handle);
|
||||
* struct nl_cache *cache = rtnl_neigh_alloc_cache(sk);
|
||||
*
|
||||
* // Neighbours can then be looked up by the interface and destination
|
||||
* // address:
|
||||
|
@ -86,7 +86,7 @@
|
|||
* // block until the operation has been completed. Alternatively the required
|
||||
* // netlink message can be built using rtnl_neigh_build_add_request()
|
||||
* // to be sent out using nl_send_auto_complete().
|
||||
* rtnl_neigh_add(nl_handle, neigh, NLM_F_REPLACE);
|
||||
* rtnl_neigh_add(sk, neigh, NLM_F_REPLACE);
|
||||
*
|
||||
* // Free the memory
|
||||
* rtnl_neigh_put(neigh);
|
||||
|
@ -109,7 +109,7 @@
|
|||
* // block until the operation has been completed. Alternatively the required
|
||||
* // netlink message can be built using rtnl_neigh_build_delete_request()
|
||||
* // to be sent out using nl_send_auto_complete().
|
||||
* rtnl_neigh_delete(handle, neigh, 0);
|
||||
* rtnl_neigh_delete(sk, neigh, 0);
|
||||
*
|
||||
* // Free the memory
|
||||
* rtnl_neigh_put(neigh);
|
||||
|
@ -139,7 +139,7 @@
|
|||
* // block until the operation has been completed. Alternatively the required
|
||||
* // netlink message can be built using rtnl_neigh_build_change_request()
|
||||
* // to be sent out using nl_send_auto_complete().
|
||||
* rtnl_neigh_change(handle, neigh, 0);
|
||||
* rtnl_neigh_change(sk, neigh, 0);
|
||||
*
|
||||
* // Free the memory
|
||||
* rtnl_neigh_put(neigh);
|
||||
|
@ -327,7 +327,7 @@ errout:
|
|||
return err;
|
||||
}
|
||||
|
||||
static int neigh_request_update(struct nl_cache *c, struct nl_handle *h)
|
||||
static int neigh_request_update(struct nl_cache *c, struct nl_sock *h)
|
||||
{
|
||||
return nl_rtgen_request(h, RTM_GETNEIGH, AF_UNSPEC, NLM_F_DUMP);
|
||||
}
|
||||
|
@ -524,7 +524,7 @@ void rtnl_neigh_put(struct rtnl_neigh *neigh)
|
|||
|
||||
/**
|
||||
* Build a neighbour cache including all neighbours currently configured in the kernel.
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg result Pointer to store resulting cache.
|
||||
*
|
||||
* Allocates a new neighbour cache, initializes it properly and updates it
|
||||
|
@ -532,7 +532,7 @@ void rtnl_neigh_put(struct rtnl_neigh *neigh)
|
|||
*
|
||||
* @return 0 on success or a negative error code.
|
||||
*/
|
||||
int rtnl_neigh_alloc_cache(struct nl_handle *sock, struct nl_cache **result)
|
||||
int rtnl_neigh_alloc_cache(struct nl_sock *sock, struct nl_cache **result)
|
||||
{
|
||||
return nl_cache_alloc_and_fill(&rtnl_neigh_ops, sock, result);
|
||||
}
|
||||
|
@ -629,7 +629,7 @@ int rtnl_neigh_build_add_request(struct rtnl_neigh *tmpl, int flags,
|
|||
|
||||
/**
|
||||
* Add a new neighbour
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg tmpl template with requested changes
|
||||
* @arg flags additional netlink message flags
|
||||
*
|
||||
|
@ -645,7 +645,7 @@ int rtnl_neigh_build_add_request(struct rtnl_neigh *tmpl, int flags,
|
|||
*
|
||||
* @return 0 on sucess or a negative error if an error occured.
|
||||
*/
|
||||
int rtnl_neigh_add(struct nl_handle *handle, struct rtnl_neigh *tmpl, int flags)
|
||||
int rtnl_neigh_add(struct nl_sock *sk, struct rtnl_neigh *tmpl, int flags)
|
||||
{
|
||||
int err;
|
||||
struct nl_msg *msg;
|
||||
|
@ -653,11 +653,11 @@ int rtnl_neigh_add(struct nl_handle *handle, struct rtnl_neigh *tmpl, int flags)
|
|||
if ((err = rtnl_neigh_build_add_request(tmpl, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
if ((err = nl_send_auto_complete(handle, msg)) < 0)
|
||||
if ((err = nl_send_auto_complete(sk, msg)) < 0)
|
||||
return err;
|
||||
|
||||
nlmsg_free(msg);
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -689,7 +689,7 @@ int rtnl_neigh_build_delete_request(struct rtnl_neigh *neigh, int flags,
|
|||
|
||||
/**
|
||||
* Delete a neighbour
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg neigh neighbour to delete
|
||||
* @arg flags additional netlink message flags
|
||||
*
|
||||
|
@ -699,7 +699,7 @@ int rtnl_neigh_build_delete_request(struct rtnl_neigh *neigh, int flags,
|
|||
*
|
||||
* @return 0 on sucess or a negative error if an error occured.
|
||||
*/
|
||||
int rtnl_neigh_delete(struct nl_handle *handle, struct rtnl_neigh *neigh,
|
||||
int rtnl_neigh_delete(struct nl_sock *sk, struct rtnl_neigh *neigh,
|
||||
int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
|
@ -708,11 +708,11 @@ int rtnl_neigh_delete(struct nl_handle *handle, struct rtnl_neigh *neigh,
|
|||
if ((err = rtnl_neigh_build_delete_request(neigh, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
if ((err = nl_send_auto_complete(handle, msg)) < 0)
|
||||
if ((err = nl_send_auto_complete(sk, msg)) < 0)
|
||||
return err;
|
||||
|
||||
nlmsg_free(msg);
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -747,7 +747,7 @@ int rtnl_neigh_build_change_request(struct rtnl_neigh *neigh, int flags,
|
|||
|
||||
/**
|
||||
* Change neighbour attributes
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg neigh neighbour to be changed
|
||||
* @arg flags additional netlink message flags
|
||||
*
|
||||
|
@ -759,8 +759,7 @@ int rtnl_neigh_build_change_request(struct rtnl_neigh *neigh, int flags,
|
|||
* @note Not all attributes can be changed, see
|
||||
* \ref neigh_changeable "Changeable Attributes" for a list.
|
||||
*/
|
||||
int rtnl_neigh_change(struct nl_handle *handle, struct rtnl_neigh *neigh,
|
||||
int flags)
|
||||
int rtnl_neigh_change(struct nl_sock *sk, struct rtnl_neigh *neigh, int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -768,11 +767,11 @@ int rtnl_neigh_change(struct nl_handle *handle, struct rtnl_neigh *neigh,
|
|||
if ((err = rtnl_neigh_build_change_request(neigh, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
if ((err = nl_send_auto_complete(handle, msg)) < 0)
|
||||
if ((err = nl_send_auto_complete(sk, msg)) < 0)
|
||||
return err;
|
||||
|
||||
nlmsg_free(msg);
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -226,7 +226,7 @@ errout:
|
|||
return err;
|
||||
}
|
||||
|
||||
static int neightbl_request_update(struct nl_cache *c, struct nl_handle *h)
|
||||
static int neightbl_request_update(struct nl_cache *c, struct nl_sock *h)
|
||||
{
|
||||
return nl_rtgen_request(h, RTM_GETNEIGHTBL, AF_UNSPEC, NLM_F_DUMP);
|
||||
}
|
||||
|
@ -394,7 +394,7 @@ void rtnl_neightbl_put(struct rtnl_neightbl *neightbl)
|
|||
|
||||
/**
|
||||
* Build a neighbour table cache including all neighbour tables currently configured in the kernel.
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg result Pointer to store resulting cache.
|
||||
*
|
||||
* Allocates a new neighbour table cache, initializes it properly and
|
||||
|
@ -403,9 +403,9 @@ void rtnl_neightbl_put(struct rtnl_neightbl *neightbl)
|
|||
*
|
||||
* @return 0 on success or a negative error code.
|
||||
*/
|
||||
int rtnl_neightbl_alloc_cache(struct nl_handle *sock, struct nl_cache **result)
|
||||
int rtnl_neightbl_alloc_cache(struct nl_sock *sk, struct nl_cache **result)
|
||||
{
|
||||
return nl_cache_alloc_and_fill(&rtnl_neightbl_ops, sock, result);
|
||||
return nl_cache_alloc_and_fill(&rtnl_neightbl_ops, sk, result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -570,7 +570,7 @@ nla_put_failure:
|
|||
|
||||
/**
|
||||
* Change neighbour table attributes
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg old neighbour table to be changed
|
||||
* @arg tmpl template with requested changes
|
||||
*
|
||||
|
@ -581,7 +581,7 @@ nla_put_failure:
|
|||
*
|
||||
* @return 0 on success or a negative error code
|
||||
*/
|
||||
int rtnl_neightbl_change(struct nl_handle *handle, struct rtnl_neightbl *old,
|
||||
int rtnl_neightbl_change(struct nl_sock *sk, struct rtnl_neightbl *old,
|
||||
struct rtnl_neightbl *tmpl)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
|
@ -590,11 +590,11 @@ int rtnl_neightbl_change(struct nl_handle *handle, struct rtnl_neightbl *old,
|
|||
if ((err = rtnl_neightbl_build_change_request(old, tmpl, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
if ((err = nl_send_auto_complete(handle, msg)) < 0)
|
||||
if ((err = nl_send_auto_complete(sk, msg)) < 0)
|
||||
return err;
|
||||
|
||||
nlmsg_free(msg);
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -133,14 +133,14 @@ errout:
|
|||
return err;
|
||||
}
|
||||
|
||||
static int qdisc_request_update(struct nl_cache *c, struct nl_handle *h)
|
||||
static int qdisc_request_update(struct nl_cache *c, struct nl_sock *sk)
|
||||
{
|
||||
struct tcmsg tchdr = {
|
||||
.tcm_family = AF_UNSPEC,
|
||||
.tcm_ifindex = c->c_iarg1,
|
||||
};
|
||||
|
||||
return nl_send_simple(h, RTM_GETQDISC, NLM_F_DUMP, &tchdr,
|
||||
return nl_send_simple(sk, RTM_GETQDISC, NLM_F_DUMP, &tchdr,
|
||||
sizeof(tchdr));
|
||||
}
|
||||
|
||||
|
@ -211,7 +211,7 @@ int rtnl_qdisc_build_add_request(struct rtnl_qdisc *qdisc, int flags,
|
|||
|
||||
/**
|
||||
* Add a new qdisc
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg qdisc qdisc to delete
|
||||
* @arg flags additional netlink message flags
|
||||
*
|
||||
|
@ -224,7 +224,7 @@ int rtnl_qdisc_build_add_request(struct rtnl_qdisc *qdisc, int flags,
|
|||
*
|
||||
* @return 0 on success or a negative error code
|
||||
*/
|
||||
int rtnl_qdisc_add(struct nl_handle *handle, struct rtnl_qdisc *qdisc,
|
||||
int rtnl_qdisc_add(struct nl_sock *sk, struct rtnl_qdisc *qdisc,
|
||||
int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
|
@ -233,11 +233,11 @@ int rtnl_qdisc_add(struct nl_handle *handle, struct rtnl_qdisc *qdisc,
|
|||
if ((err = rtnl_qdisc_build_add_request(qdisc, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
if ((err = nl_send_auto_complete(handle, msg)) < 0)
|
||||
if ((err = nl_send_auto_complete(sk, msg)) < 0)
|
||||
return err;
|
||||
|
||||
nlmsg_free(msg);
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -269,7 +269,7 @@ int rtnl_qdisc_build_change_request(struct rtnl_qdisc *qdisc,
|
|||
|
||||
/**
|
||||
* Change attributes of a qdisc
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg qdisc qdisc to change
|
||||
* @arg new new qdisc attributes
|
||||
*
|
||||
|
@ -279,7 +279,7 @@ int rtnl_qdisc_build_change_request(struct rtnl_qdisc *qdisc,
|
|||
*
|
||||
* @return 0 on success or a negative error code
|
||||
*/
|
||||
int rtnl_qdisc_change(struct nl_handle *handle, struct rtnl_qdisc *qdisc,
|
||||
int rtnl_qdisc_change(struct nl_sock *sk, struct rtnl_qdisc *qdisc,
|
||||
struct rtnl_qdisc *new)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
|
@ -288,11 +288,11 @@ int rtnl_qdisc_change(struct nl_handle *handle, struct rtnl_qdisc *qdisc,
|
|||
if ((err = rtnl_qdisc_build_change_request(qdisc, new, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
if ((err = nl_send_auto_complete(handle, msg)) < 0)
|
||||
if ((err = nl_send_auto_complete(sk, msg)) < 0)
|
||||
return err;
|
||||
|
||||
nlmsg_free(msg);
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -343,7 +343,7 @@ int rtnl_qdisc_build_delete_request(struct rtnl_qdisc *qdisc,
|
|||
|
||||
/**
|
||||
* Delete a qdisc
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg qdisc qdisc to delete
|
||||
*
|
||||
* Builds a netlink message by calling rtnl_qdisc_build_delete_request(),
|
||||
|
@ -352,7 +352,7 @@ int rtnl_qdisc_build_delete_request(struct rtnl_qdisc *qdisc,
|
|||
*
|
||||
* @return 0 on success or a negative error code
|
||||
*/
|
||||
int rtnl_qdisc_delete(struct nl_handle *handle, struct rtnl_qdisc *qdisc)
|
||||
int rtnl_qdisc_delete(struct nl_sock *sk, struct rtnl_qdisc *qdisc)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -360,11 +360,11 @@ int rtnl_qdisc_delete(struct nl_handle *handle, struct rtnl_qdisc *qdisc)
|
|||
if ((err = rtnl_qdisc_build_delete_request(qdisc, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
if ((err = nl_send_auto_complete(handle, msg)) < 0)
|
||||
if ((err = nl_send_auto_complete(sk, msg)) < 0)
|
||||
return err;
|
||||
|
||||
nlmsg_free(msg);
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -377,7 +377,7 @@ int rtnl_qdisc_delete(struct nl_handle *handle, struct rtnl_qdisc *qdisc)
|
|||
/**
|
||||
* Build a qdisc cache including all qdiscs currently configured in
|
||||
* the kernel
|
||||
* @arg sock netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg result Pointer to store resulting message.
|
||||
*
|
||||
* Allocates a new cache, initializes it properly and updates it to
|
||||
|
@ -385,9 +385,9 @@ int rtnl_qdisc_delete(struct nl_handle *handle, struct rtnl_qdisc *qdisc)
|
|||
*
|
||||
* @return 0 on success or a negative error code.
|
||||
*/
|
||||
int rtnl_qdisc_alloc_cache(struct nl_handle *sock, struct nl_cache **result)
|
||||
int rtnl_qdisc_alloc_cache(struct nl_sock *sk, struct nl_cache **result)
|
||||
{
|
||||
return nl_cache_alloc_and_fill(&rtnl_qdisc_ops, sock, result);
|
||||
return nl_cache_alloc_and_fill(&rtnl_qdisc_ops, sk, result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,7 +46,7 @@ errout:
|
|||
return err;
|
||||
}
|
||||
|
||||
static int route_request_update(struct nl_cache *c, struct nl_handle *h)
|
||||
static int route_request_update(struct nl_cache *c, struct nl_sock *h)
|
||||
{
|
||||
struct rtmsg rhdr = {
|
||||
.rtm_family = c->c_iarg1,
|
||||
|
@ -65,7 +65,7 @@ static int route_request_update(struct nl_cache *c, struct nl_handle *h)
|
|||
|
||||
/**
|
||||
* Build a route cache holding all routes currently configured in the kernel
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg family Address family of routes to cover or AF_UNSPEC
|
||||
* @arg flags Flags
|
||||
*
|
||||
|
@ -76,7 +76,7 @@ static int route_request_update(struct nl_cache *c, struct nl_handle *h)
|
|||
* cache after using it.
|
||||
* @return The cache or NULL if an error has occured.
|
||||
*/
|
||||
int rtnl_route_alloc_cache(struct nl_handle *handle, int family, int flags,
|
||||
int rtnl_route_alloc_cache(struct nl_sock *sk, int family, int flags,
|
||||
struct nl_cache **result)
|
||||
{
|
||||
struct nl_cache *cache;
|
||||
|
@ -88,7 +88,7 @@ int rtnl_route_alloc_cache(struct nl_handle *handle, int family, int flags,
|
|||
cache->c_iarg1 = family;
|
||||
cache->c_iarg2 = flags;
|
||||
|
||||
if (handle && (err = nl_cache_refill(handle, cache)) < 0) {
|
||||
if (sk && (err = nl_cache_refill(sk, cache)) < 0) {
|
||||
free(cache);
|
||||
return err;
|
||||
}
|
||||
|
@ -129,8 +129,7 @@ int rtnl_route_build_add_request(struct rtnl_route *tmpl, int flags,
|
|||
result);
|
||||
}
|
||||
|
||||
int rtnl_route_add(struct nl_handle *handle, struct rtnl_route *route,
|
||||
int flags)
|
||||
int rtnl_route_add(struct nl_sock *sk, struct rtnl_route *route, int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -138,12 +137,12 @@ int rtnl_route_add(struct nl_handle *handle, struct rtnl_route *route,
|
|||
if ((err = rtnl_route_build_add_request(route, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
err = nl_send_auto_complete(handle, msg);
|
||||
err = nl_send_auto_complete(sk, msg);
|
||||
nlmsg_free(msg);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
int rtnl_route_build_del_request(struct rtnl_route *tmpl, int flags,
|
||||
|
@ -152,8 +151,7 @@ int rtnl_route_build_del_request(struct rtnl_route *tmpl, int flags,
|
|||
return build_route_msg(tmpl, RTM_DELROUTE, flags, result);
|
||||
}
|
||||
|
||||
int rtnl_route_delete(struct nl_handle *handle, struct rtnl_route *route,
|
||||
int flags)
|
||||
int rtnl_route_delete(struct nl_sock *sk, struct rtnl_route *route, int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -161,12 +159,12 @@ int rtnl_route_delete(struct nl_handle *handle, struct rtnl_route *route,
|
|||
if ((err = rtnl_route_build_del_request(route, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
err = nl_send_auto_complete(handle, msg);
|
||||
err = nl_send_auto_complete(sk, msg);
|
||||
nlmsg_free(msg);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
|
||||
* Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -27,7 +27,7 @@
|
|||
|
||||
/**
|
||||
* Send routing netlink request message
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg type Netlink message type.
|
||||
* @arg family Address family.
|
||||
* @arg flags Additional netlink message flags.
|
||||
|
@ -37,13 +37,13 @@
|
|||
*
|
||||
* @return 0 on success or a negative error code.
|
||||
*/
|
||||
int nl_rtgen_request(struct nl_handle *handle, int type, int family, int flags)
|
||||
int nl_rtgen_request(struct nl_sock *sk, int type, int family, int flags)
|
||||
{
|
||||
struct rtgenmsg gmsg = {
|
||||
.rtgen_family = family,
|
||||
};
|
||||
|
||||
return nl_send_simple(handle, type, flags, &gmsg, sizeof(gmsg));
|
||||
return nl_send_simple(sk, type, flags, &gmsg, sizeof(gmsg));
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -169,7 +169,7 @@ errout_enomem:
|
|||
goto errout;
|
||||
}
|
||||
|
||||
static int rule_request_update(struct nl_cache *c, struct nl_handle *h)
|
||||
static int rule_request_update(struct nl_cache *c, struct nl_sock *h)
|
||||
{
|
||||
return nl_rtgen_request(h, RTM_GETRULE, AF_UNSPEC, NLM_F_DUMP);
|
||||
}
|
||||
|
@ -435,7 +435,7 @@ void rtnl_rule_put(struct rtnl_rule *rule)
|
|||
|
||||
/**
|
||||
* Build a rule cache including all rules currently configured in the kernel.
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg family Address family or AF_UNSPEC.
|
||||
* @arg result Pointer to store resulting cache.
|
||||
*
|
||||
|
@ -444,7 +444,7 @@ void rtnl_rule_put(struct rtnl_rule *rule)
|
|||
*
|
||||
* @return 0 on success or a negative error code.
|
||||
*/
|
||||
int rtnl_rule_alloc_cache(struct nl_handle *sock, int family,
|
||||
int rtnl_rule_alloc_cache(struct nl_sock *sock, int family,
|
||||
struct nl_cache **result)
|
||||
{
|
||||
struct nl_cache * cache;
|
||||
|
@ -555,7 +555,7 @@ int rtnl_rule_build_add_request(struct rtnl_rule *tmpl, int flags,
|
|||
|
||||
/**
|
||||
* Add a new rule
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg tmpl template with requested changes
|
||||
* @arg flags additional netlink message flags
|
||||
*
|
||||
|
@ -565,7 +565,7 @@ int rtnl_rule_build_add_request(struct rtnl_rule *tmpl, int flags,
|
|||
*
|
||||
* @return 0 on sucess or a negative error if an error occured.
|
||||
*/
|
||||
int rtnl_rule_add(struct nl_handle *handle, struct rtnl_rule *tmpl, int flags)
|
||||
int rtnl_rule_add(struct nl_sock *sk, struct rtnl_rule *tmpl, int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -573,12 +573,12 @@ int rtnl_rule_add(struct nl_handle *handle, struct rtnl_rule *tmpl, int flags)
|
|||
if ((err = rtnl_rule_build_add_request(tmpl, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
err = nl_send_auto_complete(handle, msg);
|
||||
err = nl_send_auto_complete(sk, msg);
|
||||
nlmsg_free(msg);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -609,7 +609,7 @@ int rtnl_rule_build_delete_request(struct rtnl_rule *rule, int flags,
|
|||
|
||||
/**
|
||||
* Delete a rule
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg rule rule to delete
|
||||
* @arg flags additional netlink message flags
|
||||
*
|
||||
|
@ -619,8 +619,7 @@ int rtnl_rule_build_delete_request(struct rtnl_rule *rule, int flags,
|
|||
*
|
||||
* @return 0 on sucess or a negative error if an error occured.
|
||||
*/
|
||||
int rtnl_rule_delete(struct nl_handle *handle, struct rtnl_rule *rule,
|
||||
int flags)
|
||||
int rtnl_rule_delete(struct nl_sock *sk, struct rtnl_rule *rule, int flags)
|
||||
{
|
||||
struct nl_msg *msg;
|
||||
int err;
|
||||
|
@ -628,12 +627,12 @@ int rtnl_rule_delete(struct nl_handle *handle, struct rtnl_rule *rule,
|
|||
if ((err = rtnl_rule_build_delete_request(rule, flags, &msg)) < 0)
|
||||
return err;
|
||||
|
||||
err = nl_send_auto_complete(handle, msg);
|
||||
err = nl_send_auto_complete(sk, msg);
|
||||
nlmsg_free(msg);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
return nl_wait_for_ack(handle);
|
||||
return nl_wait_for_ack(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
233
lib/socket.c
233
lib/socket.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* lib/socket.c Netlink Socket Handle
|
||||
* lib/socket.c Netlink Socket
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -12,19 +12,16 @@
|
|||
/**
|
||||
* @ingroup nl
|
||||
* @defgroup socket Socket
|
||||
* @brief Handle representing a netlink socket.
|
||||
*
|
||||
* The socket is represented in a structure called the netlink handle,
|
||||
* besides the socket, it stores various settings and values related
|
||||
* to the socket. Every socket handle has a mandatory association with
|
||||
* a set of callbacks which can be used to modify the behaviour when
|
||||
* sending/receiving data from the socket.
|
||||
* Every socket has a mandatory association with a set of callbacks
|
||||
* which can be used to modify the behaviour when sending/receiving data
|
||||
* from the socket.
|
||||
*
|
||||
* @par Socket Attributes
|
||||
* - \b Local \b Port: The local port is a netlink port identifying the
|
||||
* local endpoint. It is used as source address for outgoing messages
|
||||
* and will be addressed in replies. It must therefore be unique among
|
||||
* all userspace applications. When the socket handle is allocated, a
|
||||
* all userspace applications. When the socket is allocated, a
|
||||
* unique port number is generated automatically in the form of 22 bits
|
||||
* Process Identifier + 10 bits Arbitary Number. Therefore the library
|
||||
* is capable of generating 1024 unique local port numbers for every
|
||||
|
@ -61,29 +58,29 @@
|
|||
* number.)
|
||||
* - \b Callbacks \b Configuration:
|
||||
*
|
||||
* @par 1) Creating the netlink handle
|
||||
* @par 1) Creating the netlink socket
|
||||
* @code
|
||||
* struct nl_handle *handle;
|
||||
* struct nl_sock *sk;
|
||||
*
|
||||
* // Allocate and initialize a new netlink handle
|
||||
* handle = nl_handle_alloc();
|
||||
* // Allocate and initialize a new netlink socket
|
||||
* sk = nl_socket_alloc();
|
||||
*
|
||||
* // Use nl_socket_get_fd() to fetch the file description, for example to
|
||||
* // put a socket into non-blocking i/o mode.
|
||||
* fcntl(nl_socket_get_fd(handle), F_SETFL, O_NONBLOCK);
|
||||
* fcntl(nl_socket_get_fd(sk), F_SETFL, O_NONBLOCK);
|
||||
* @endcode
|
||||
*
|
||||
* @par 2) Group Subscriptions
|
||||
* @code
|
||||
* // Event notifications are typically sent to multicast addresses which
|
||||
* // represented by groups. Join a group to f.e. receive link notifications.
|
||||
* nl_socket_add_membership(handle, RTNLGRP_LINK);
|
||||
* nl_socket_add_membership(sk, RTNLGRP_LINK);
|
||||
* @endcode
|
||||
*
|
||||
* @par 6) Cleaning up
|
||||
* @code
|
||||
* // Finally destroy the netlink handle
|
||||
* nl_handle_destroy(handle);
|
||||
* // Finally destroy the netlink socket.
|
||||
* nl_socket_free(sk);
|
||||
* @endcode
|
||||
*
|
||||
* @{
|
||||
|
@ -161,34 +158,34 @@ static void release_local_port(uint32_t port)
|
|||
* @{
|
||||
*/
|
||||
|
||||
static struct nl_handle *__alloc_handle(struct nl_cb *cb)
|
||||
static struct nl_sock *__alloc_socket(struct nl_cb *cb)
|
||||
{
|
||||
struct nl_handle *handle;
|
||||
struct nl_sock *sk;
|
||||
|
||||
handle = calloc(1, sizeof(*handle));
|
||||
if (!handle)
|
||||
sk = calloc(1, sizeof(*sk));
|
||||
if (!sk)
|
||||
return NULL;
|
||||
|
||||
handle->h_fd = -1;
|
||||
handle->h_cb = cb;
|
||||
handle->h_local.nl_family = AF_NETLINK;
|
||||
handle->h_peer.nl_family = AF_NETLINK;
|
||||
handle->h_seq_expect = handle->h_seq_next = time(0);
|
||||
handle->h_local.nl_pid = generate_local_port();
|
||||
if (handle->h_local.nl_pid == UINT_MAX) {
|
||||
nl_handle_destroy(handle);
|
||||
sk->s_fd = -1;
|
||||
sk->s_cb = cb;
|
||||
sk->s_local.nl_family = AF_NETLINK;
|
||||
sk->s_peer.nl_family = AF_NETLINK;
|
||||
sk->s_seq_expect = sk->s_seq_next = time(0);
|
||||
sk->s_local.nl_pid = generate_local_port();
|
||||
if (sk->s_local.nl_pid == UINT_MAX) {
|
||||
nl_socket_free(sk);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return handle;
|
||||
return sk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate new netlink socket handle.
|
||||
* Allocate new netlink socket
|
||||
*
|
||||
* @return Newly allocated netlink socket handle or NULL.
|
||||
* @return Newly allocated netlink socket or NULL.
|
||||
*/
|
||||
struct nl_handle *nl_handle_alloc(void)
|
||||
struct nl_sock *nl_socket_alloc(void)
|
||||
{
|
||||
struct nl_cb *cb;
|
||||
|
||||
|
@ -196,43 +193,43 @@ struct nl_handle *nl_handle_alloc(void)
|
|||
if (!cb)
|
||||
return NULL;
|
||||
|
||||
return __alloc_handle(cb);
|
||||
return __alloc_socket(cb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate new socket handle with custom callbacks
|
||||
* Allocate new socket with custom callbacks
|
||||
* @arg cb Callback handler
|
||||
*
|
||||
* The reference to the callback handler is taken into account
|
||||
* automatically, it is released again upon calling nl_handle_destroy().
|
||||
* automatically, it is released again upon calling nl_socket_free().
|
||||
*
|
||||
*@return Newly allocted socket handle or NULL.
|
||||
*/
|
||||
struct nl_handle *nl_handle_alloc_cb(struct nl_cb *cb)
|
||||
struct nl_sock *nl_socket_alloc_cb(struct nl_cb *cb)
|
||||
{
|
||||
if (cb == NULL)
|
||||
BUG();
|
||||
|
||||
return __alloc_handle(nl_cb_get(cb));
|
||||
return __alloc_socket(nl_cb_get(cb));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy netlink handle.
|
||||
* @arg handle Netlink handle.
|
||||
* Free a netlink socket.
|
||||
* @arg sk Netlink socket.
|
||||
*/
|
||||
void nl_handle_destroy(struct nl_handle *handle)
|
||||
void nl_socket_free(struct nl_sock *sk)
|
||||
{
|
||||
if (!handle)
|
||||
if (!sk)
|
||||
return;
|
||||
|
||||
if (handle->h_fd >= 0)
|
||||
close(handle->h_fd);
|
||||
if (sk->s_fd >= 0)
|
||||
close(sk->s_fd);
|
||||
|
||||
if (!(handle->h_flags & NL_OWN_PORT))
|
||||
release_local_port(handle->h_local.nl_pid);
|
||||
if (!(sk->s_flags & NL_OWN_PORT))
|
||||
release_local_port(sk->s_local.nl_pid);
|
||||
|
||||
nl_cb_put(handle->h_cb);
|
||||
free(handle);
|
||||
nl_cb_put(sk->s_cb);
|
||||
free(sk);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -250,33 +247,33 @@ static int noop_seq_check(struct nl_msg *msg, void *arg)
|
|||
|
||||
/**
|
||||
* Disable sequence number checking.
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
*
|
||||
* Disables checking of sequence numbers on the netlink handle. This is
|
||||
* Disables checking of sequence numbers on the netlink socket This is
|
||||
* required to allow messages to be processed which were not requested by
|
||||
* a preceding request message, e.g. netlink events.
|
||||
*
|
||||
* @note This function modifies the NL_CB_SEQ_CHECK configuration in
|
||||
* the callback handle associated with the socket.
|
||||
*/
|
||||
void nl_disable_sequence_check(struct nl_handle *handle)
|
||||
void nl_disable_sequence_check(struct nl_sock *sk)
|
||||
{
|
||||
nl_cb_set(handle->h_cb, NL_CB_SEQ_CHECK,
|
||||
nl_cb_set(sk->s_cb, NL_CB_SEQ_CHECK,
|
||||
NL_CB_CUSTOM, noop_seq_check, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use next sequence number
|
||||
* @arg handle Netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
*
|
||||
* Uses the next available sequence number and increases the counter
|
||||
* by one for subsequent calls.
|
||||
*
|
||||
* @return Unique serial sequence number
|
||||
*/
|
||||
unsigned int nl_socket_use_seq(struct nl_handle *handle)
|
||||
unsigned int nl_socket_use_seq(struct nl_sock *sk)
|
||||
{
|
||||
return handle->h_seq_next++;
|
||||
return sk->s_seq_next++;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -286,31 +283,31 @@ unsigned int nl_socket_use_seq(struct nl_handle *handle)
|
|||
* @{
|
||||
*/
|
||||
|
||||
uint32_t nl_socket_get_local_port(struct nl_handle *handle)
|
||||
uint32_t nl_socket_get_local_port(struct nl_sock *sk)
|
||||
{
|
||||
return handle->h_local.nl_pid;
|
||||
return sk->s_local.nl_pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set local port of socket
|
||||
* @arg handle Netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg port Local port identifier
|
||||
*
|
||||
* Assigns a local port identifier to the socket. If port is 0
|
||||
* a unique port identifier will be generated automatically.
|
||||
*/
|
||||
void nl_socket_set_local_port(struct nl_handle *handle, uint32_t port)
|
||||
void nl_socket_set_local_port(struct nl_sock *sk, uint32_t port)
|
||||
{
|
||||
if (port == 0) {
|
||||
port = generate_local_port();
|
||||
handle->h_flags &= ~NL_OWN_PORT;
|
||||
sk->s_flags &= ~NL_OWN_PORT;
|
||||
} else {
|
||||
if (!(handle->h_flags & NL_OWN_PORT))
|
||||
release_local_port(handle->h_local.nl_pid);
|
||||
handle->h_flags |= NL_OWN_PORT;
|
||||
if (!(sk->s_flags & NL_OWN_PORT))
|
||||
release_local_port(sk->s_local.nl_pid);
|
||||
sk->s_flags |= NL_OWN_PORT;
|
||||
}
|
||||
|
||||
handle->h_local.nl_pid = port;
|
||||
sk->s_local.nl_pid = port;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -322,7 +319,7 @@ void nl_socket_set_local_port(struct nl_handle *handle, uint32_t port)
|
|||
|
||||
/**
|
||||
* Join a group
|
||||
* @arg handle Netlink handle
|
||||
* @arg sk Netlink socket
|
||||
* @arg group Group identifier
|
||||
*
|
||||
* Joins the specified group using the modern socket option which
|
||||
|
@ -335,14 +332,14 @@ void nl_socket_set_local_port(struct nl_handle *handle, uint32_t port)
|
|||
*
|
||||
* @return 0 on sucess or a negative error code.
|
||||
*/
|
||||
int nl_socket_add_membership(struct nl_handle *handle, int group)
|
||||
int nl_socket_add_membership(struct nl_sock *sk, int group)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (handle->h_fd == -1)
|
||||
if (sk->s_fd == -1)
|
||||
return -NLE_BAD_SOCK;
|
||||
|
||||
err = setsockopt(handle->h_fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP,
|
||||
err = setsockopt(sk->s_fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP,
|
||||
&group, sizeof(group));
|
||||
if (err < 0)
|
||||
return -nl_syserr2nlerr(errno);
|
||||
|
@ -352,7 +349,7 @@ int nl_socket_add_membership(struct nl_handle *handle, int group)
|
|||
|
||||
/**
|
||||
* Leave a group
|
||||
* @arg handle Netlink handle
|
||||
* @arg sk Netlink socket
|
||||
* @arg group Group identifier
|
||||
*
|
||||
* Leaves the specified group using the modern socket option
|
||||
|
@ -361,14 +358,14 @@ int nl_socket_add_membership(struct nl_handle *handle, int group)
|
|||
* @see nl_socket_add_membership
|
||||
* @return 0 on success or a negative error code.
|
||||
*/
|
||||
int nl_socket_drop_membership(struct nl_handle *handle, int group)
|
||||
int nl_socket_drop_membership(struct nl_sock *sk, int group)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (handle->h_fd == -1)
|
||||
if (sk->s_fd == -1)
|
||||
return -NLE_BAD_SOCK;
|
||||
|
||||
err = setsockopt(handle->h_fd, SOL_NETLINK, NETLINK_DROP_MEMBERSHIP,
|
||||
err = setsockopt(sk->s_fd, SOL_NETLINK, NETLINK_DROP_MEMBERSHIP,
|
||||
&group, sizeof(group));
|
||||
if (err < 0)
|
||||
return -nl_syserr2nlerr(errno);
|
||||
|
@ -378,16 +375,16 @@ int nl_socket_drop_membership(struct nl_handle *handle, int group)
|
|||
|
||||
/**
|
||||
* Join multicast groups (deprecated)
|
||||
* @arg handle Netlink handle.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg groups Bitmask of groups to join.
|
||||
*
|
||||
* This function defines the old way of joining multicast group which
|
||||
* has to be done prior to calling nl_connect(). It works on any kernel
|
||||
* version but is very limited as only 32 groups can be joined.
|
||||
*/
|
||||
void nl_join_groups(struct nl_handle *handle, int groups)
|
||||
void nl_join_groups(struct nl_sock *sk, int groups)
|
||||
{
|
||||
handle->h_local.nl_groups |= groups;
|
||||
sk->s_local.nl_groups |= groups;
|
||||
}
|
||||
|
||||
|
||||
|
@ -398,14 +395,14 @@ void nl_join_groups(struct nl_handle *handle, int groups)
|
|||
* @{
|
||||
*/
|
||||
|
||||
uint32_t nl_socket_get_peer_port(struct nl_handle *handle)
|
||||
uint32_t nl_socket_get_peer_port(struct nl_sock *sk)
|
||||
{
|
||||
return handle->h_peer.nl_pid;
|
||||
return sk->s_peer.nl_pid;
|
||||
}
|
||||
|
||||
void nl_socket_set_peer_port(struct nl_handle *handle, uint32_t port)
|
||||
void nl_socket_set_peer_port(struct nl_sock *sk, uint32_t port)
|
||||
{
|
||||
handle->h_peer.nl_pid = port;
|
||||
sk->s_peer.nl_pid = port;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -415,23 +412,23 @@ void nl_socket_set_peer_port(struct nl_handle *handle, uint32_t port)
|
|||
* @{
|
||||
*/
|
||||
|
||||
int nl_socket_get_fd(struct nl_handle *handle)
|
||||
int nl_socket_get_fd(struct nl_sock *sk)
|
||||
{
|
||||
return handle->h_fd;
|
||||
return sk->s_fd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set file descriptor of socket handle to non-blocking state
|
||||
* @arg handle Netlink socket
|
||||
* Set file descriptor of socket to non-blocking state
|
||||
* @arg sk Netlink socket.
|
||||
*
|
||||
* @return 0 on success or a negative error code.
|
||||
*/
|
||||
int nl_socket_set_nonblocking(struct nl_handle *handle)
|
||||
int nl_socket_set_nonblocking(struct nl_sock *sk)
|
||||
{
|
||||
if (handle->h_fd == -1)
|
||||
if (sk->s_fd == -1)
|
||||
return -NLE_BAD_SOCK;
|
||||
|
||||
if (fcntl(handle->h_fd, F_SETFL, O_NONBLOCK) < 0)
|
||||
if (fcntl(sk->s_fd, F_SETFL, O_NONBLOCK) < 0)
|
||||
return -nl_syserr2nlerr(errno);
|
||||
|
||||
return 0;
|
||||
|
@ -439,20 +436,20 @@ int nl_socket_set_nonblocking(struct nl_handle *handle)
|
|||
|
||||
/**
|
||||
* Enable use of MSG_PEEK when reading from socket
|
||||
* @arg handle Netlink socket
|
||||
* @arg sk Netlink socket.
|
||||
*/
|
||||
void nl_socket_enable_msg_peek(struct nl_handle *handle)
|
||||
void nl_socket_enable_msg_peek(struct nl_sock *sk)
|
||||
{
|
||||
handle->h_flags |= NL_MSG_PEEK;
|
||||
sk->s_flags |= NL_MSG_PEEK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable use of MSG_PEEK when reading from socket
|
||||
* @arg handle Netlink socket
|
||||
* @arg sk Netlink socket.
|
||||
*/
|
||||
void nl_socket_disable_msg_peek(struct nl_handle *handle)
|
||||
void nl_socket_disable_msg_peek(struct nl_sock *sk)
|
||||
{
|
||||
handle->h_flags &= ~NL_MSG_PEEK;
|
||||
sk->s_flags &= ~NL_MSG_PEEK;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -462,20 +459,20 @@ void nl_socket_disable_msg_peek(struct nl_handle *handle)
|
|||
* @{
|
||||
*/
|
||||
|
||||
struct nl_cb *nl_socket_get_cb(struct nl_handle *handle)
|
||||
struct nl_cb *nl_socket_get_cb(struct nl_sock *sk)
|
||||
{
|
||||
return nl_cb_get(handle->h_cb);
|
||||
return nl_cb_get(sk->s_cb);
|
||||
}
|
||||
|
||||
void nl_socket_set_cb(struct nl_handle *handle, struct nl_cb *cb)
|
||||
void nl_socket_set_cb(struct nl_sock *sk, struct nl_cb *cb)
|
||||
{
|
||||
nl_cb_put(handle->h_cb);
|
||||
handle->h_cb = nl_cb_get(cb);
|
||||
nl_cb_put(sk->s_cb);
|
||||
sk->s_cb = nl_cb_get(cb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the callback handler associated to the socket
|
||||
* @arg handle netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg type which type callback to set
|
||||
* @arg kind kind of callback
|
||||
* @arg func callback function
|
||||
|
@ -483,11 +480,11 @@ void nl_socket_set_cb(struct nl_handle *handle, struct nl_cb *cb)
|
|||
*
|
||||
* @see nl_cb_set
|
||||
*/
|
||||
int nl_socket_modify_cb(struct nl_handle *handle, enum nl_cb_type type,
|
||||
int nl_socket_modify_cb(struct nl_sock *sk, enum nl_cb_type type,
|
||||
enum nl_cb_kind kind, nl_recvmsg_msg_cb_t func,
|
||||
void *arg)
|
||||
{
|
||||
return nl_cb_set(handle->h_cb, type, kind, func, arg);
|
||||
return nl_cb_set(sk->s_cb, type, kind, func, arg);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -498,19 +495,19 @@ int nl_socket_modify_cb(struct nl_handle *handle, enum nl_cb_type type,
|
|||
*/
|
||||
|
||||
/**
|
||||
* Set socket buffer size of netlink handle.
|
||||
* @arg handle Netlink handle.
|
||||
* Set socket buffer size of netlink socket.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg rxbuf New receive socket buffer size in bytes.
|
||||
* @arg txbuf New transmit socket buffer size in bytes.
|
||||
*
|
||||
* Sets the socket buffer size of a netlink handle to the specified
|
||||
* Sets the socket buffer size of a netlink socket to the specified
|
||||
* values \c rxbuf and \c txbuf. Providing a value of \c 0 assumes a
|
||||
* good default value.
|
||||
*
|
||||
* @note It is not required to call this function prior to nl_connect().
|
||||
* @return 0 on sucess or a negative error code.
|
||||
*/
|
||||
int nl_set_buffer_size(struct nl_handle *handle, int rxbuf, int txbuf)
|
||||
int nl_set_buffer_size(struct nl_sock *sk, int rxbuf, int txbuf)
|
||||
{
|
||||
int err;
|
||||
|
||||
|
@ -520,66 +517,66 @@ int nl_set_buffer_size(struct nl_handle *handle, int rxbuf, int txbuf)
|
|||
if (txbuf <= 0)
|
||||
txbuf = 32768;
|
||||
|
||||
if (handle->h_fd == -1)
|
||||
if (sk->s_fd == -1)
|
||||
return -NLE_BAD_SOCK;
|
||||
|
||||
err = setsockopt(handle->h_fd, SOL_SOCKET, SO_SNDBUF,
|
||||
err = setsockopt(sk->s_fd, SOL_SOCKET, SO_SNDBUF,
|
||||
&txbuf, sizeof(txbuf));
|
||||
if (err < 0)
|
||||
return -nl_syserr2nlerr(errno);
|
||||
|
||||
err = setsockopt(handle->h_fd, SOL_SOCKET, SO_RCVBUF,
|
||||
err = setsockopt(sk->s_fd, SOL_SOCKET, SO_RCVBUF,
|
||||
&rxbuf, sizeof(rxbuf));
|
||||
if (err < 0)
|
||||
return -nl_syserr2nlerr(errno);
|
||||
|
||||
handle->h_flags |= NL_SOCK_BUFSIZE_SET;
|
||||
sk->s_flags |= NL_SOCK_BUFSIZE_SET;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable credential passing on netlink handle.
|
||||
* @arg handle Netlink handle
|
||||
* Enable/disable credential passing on netlink socket.
|
||||
* @arg sk Netlink socket.
|
||||
* @arg state New state (0 - disabled, 1 - enabled)
|
||||
*
|
||||
* @return 0 on success or a negative error code
|
||||
*/
|
||||
int nl_set_passcred(struct nl_handle *handle, int state)
|
||||
int nl_set_passcred(struct nl_sock *sk, int state)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (handle->h_fd == -1)
|
||||
if (sk->s_fd == -1)
|
||||
return -NLE_BAD_SOCK;
|
||||
|
||||
err = setsockopt(handle->h_fd, SOL_SOCKET, SO_PASSCRED,
|
||||
err = setsockopt(sk->s_fd, SOL_SOCKET, SO_PASSCRED,
|
||||
&state, sizeof(state));
|
||||
if (err < 0)
|
||||
return -nl_syserr2nlerr(errno);
|
||||
|
||||
if (state)
|
||||
handle->h_flags |= NL_SOCK_PASSCRED;
|
||||
sk->s_flags |= NL_SOCK_PASSCRED;
|
||||
else
|
||||
handle->h_flags &= ~NL_SOCK_PASSCRED;
|
||||
sk->s_flags &= ~NL_SOCK_PASSCRED;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable receival of additional packet information
|
||||
* @arg handle Netlink handle
|
||||
* @arg sk Netlink socket.
|
||||
* @arg state New state (0 - disabled, 1 - enabled)
|
||||
*
|
||||
* @return 0 on success or a negative error code
|
||||
*/
|
||||
int nl_socket_recv_pktinfo(struct nl_handle *handle, int state)
|
||||
int nl_socket_recv_pktinfo(struct nl_sock *sk, int state)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (handle->h_fd == -1)
|
||||
if (sk->s_fd == -1)
|
||||
return -NLE_BAD_SOCK;
|
||||
|
||||
err = setsockopt(handle->h_fd, SOL_NETLINK, NETLINK_PKTINFO,
|
||||
err = setsockopt(sk->s_fd, SOL_NETLINK, NETLINK_PKTINFO,
|
||||
&state, sizeof(state));
|
||||
if (err < 0)
|
||||
return -nl_syserr2nlerr(errno);
|
||||
|
|
Loading…
Add table
Reference in a new issue