~ubuntu-branches/ubuntu/trusty/libnl3/trusty

« back to all changes in this revision

Viewing changes to include/netlink/handlers.h

  • Committer: Bazaar Package Importer
  • Author(s): Heiko Stuebner
  • Date: 2011-05-21 19:25:13 UTC
  • Revision ID: james.westby@ubuntu.com-20110521192513-1ieyu9w9kym4bt16
Tags: upstream-3.0
ImportĀ upstreamĀ versionĀ 3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * netlink/handlers.c   default netlink message handlers
 
3
 *
 
4
 *      This library is free software; you can redistribute it and/or
 
5
 *      modify it under the terms of the GNU Lesser General Public
 
6
 *      License as published by the Free Software Foundation version 2.1
 
7
 *      of the License.
 
8
 *
 
9
 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
 
10
 */
 
11
 
 
12
#ifndef NETLINK_HANDLERS_H_
 
13
#define NETLINK_HANDLERS_H_
 
14
 
 
15
#include <stdio.h>
 
16
#include <stdint.h>
 
17
#include <sys/types.h>
 
18
#include <netlink/netlink-compat.h>
 
19
#include <netlink/netlink-kernel.h>
 
20
 
 
21
#ifdef __cplusplus
 
22
extern "C" {
 
23
#endif
 
24
 
 
25
struct nl_cb;
 
26
struct nl_sock;
 
27
struct nl_msg;
 
28
struct ucred;
 
29
 
 
30
/**
 
31
 * @name Callback Typedefs
 
32
 * @{
 
33
 */
 
34
 
 
35
/**
 
36
 * nl_recvmsgs() callback for message processing customization
 
37
 * @ingroup cb
 
38
 * @arg msg             netlink message being processed
 
39
 * @arg arg             argument passwd on through caller
 
40
 */
 
41
typedef int (*nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg);
 
42
 
 
43
/**
 
44
 * nl_recvmsgs() callback for error message processing customization
 
45
 * @ingroup cb
 
46
 * @arg nla             netlink address of the peer
 
47
 * @arg nlerr           netlink error message being processed
 
48
 * @arg arg             argument passed on through caller
 
49
 */
 
50
typedef int (*nl_recvmsg_err_cb_t)(struct sockaddr_nl *nla,
 
51
                                   struct nlmsgerr *nlerr, void *arg);
 
52
 
 
53
/** @} */
 
54
 
 
55
/**
 
56
 * Callback actions
 
57
 * @ingroup cb
 
58
 */
 
59
enum nl_cb_action {
 
60
        /** Proceed with wathever would come next */
 
61
        NL_OK,
 
62
        /** Skip this message */
 
63
        NL_SKIP,
 
64
        /** Stop parsing altogether and discard remaining messages */
 
65
        NL_STOP,
 
66
};
 
67
 
 
68
/**
 
69
 * Callback kinds
 
70
 * @ingroup cb
 
71
 */
 
72
enum nl_cb_kind {
 
73
        /** Default handlers (quiet) */
 
74
        NL_CB_DEFAULT,
 
75
        /** Verbose default handlers (error messages printed) */
 
76
        NL_CB_VERBOSE,
 
77
        /** Debug handlers for debugging */
 
78
        NL_CB_DEBUG,
 
79
        /** Customized handler specified by the user */
 
80
        NL_CB_CUSTOM,
 
81
        __NL_CB_KIND_MAX,
 
82
};
 
83
 
 
84
#define NL_CB_KIND_MAX (__NL_CB_KIND_MAX - 1)
 
85
 
 
86
/**
 
87
 * Callback types
 
88
 * @ingroup cb
 
89
 */
 
90
enum nl_cb_type {
 
91
        /** Message is valid */
 
92
        NL_CB_VALID,
 
93
        /** Last message in a series of multi part messages received */
 
94
        NL_CB_FINISH,
 
95
        /** Report received that data was lost */
 
96
        NL_CB_OVERRUN,
 
97
        /** Message wants to be skipped */
 
98
        NL_CB_SKIPPED,
 
99
        /** Message is an acknowledge */
 
100
        NL_CB_ACK,
 
101
        /** Called for every message received */
 
102
        NL_CB_MSG_IN,
 
103
        /** Called for every message sent out except for nl_sendto() */
 
104
        NL_CB_MSG_OUT,
 
105
        /** Message is malformed and invalid */
 
106
        NL_CB_INVALID,
 
107
        /** Called instead of internal sequence number checking */
 
108
        NL_CB_SEQ_CHECK,
 
109
        /** Sending of an acknowledge message has been requested */
 
110
        NL_CB_SEND_ACK,
 
111
        __NL_CB_TYPE_MAX,
 
112
};
 
113
 
 
114
#define NL_CB_TYPE_MAX (__NL_CB_TYPE_MAX - 1)
 
115
 
 
116
extern struct nl_cb *   nl_cb_alloc(enum nl_cb_kind);
 
117
extern struct nl_cb *   nl_cb_clone(struct nl_cb *);
 
118
extern struct nl_cb *   nl_cb_get(struct nl_cb *);
 
119
extern void             nl_cb_put(struct nl_cb *);
 
120
 
 
121
extern int  nl_cb_set(struct nl_cb *, enum nl_cb_type, enum nl_cb_kind,
 
122
                      nl_recvmsg_msg_cb_t, void *);
 
123
extern int  nl_cb_set_all(struct nl_cb *, enum nl_cb_kind,
 
124
                          nl_recvmsg_msg_cb_t, void *);
 
125
extern int  nl_cb_err(struct nl_cb *, enum nl_cb_kind, nl_recvmsg_err_cb_t,
 
126
                      void *);
 
127
 
 
128
extern void nl_cb_overwrite_recvmsgs(struct nl_cb *,
 
129
                                     int (*func)(struct nl_sock *,
 
130
                                                 struct nl_cb *));
 
131
extern void nl_cb_overwrite_recv(struct nl_cb *,
 
132
                                 int (*func)(struct nl_sock *,
 
133
                                             struct sockaddr_nl *,
 
134
                                             unsigned char **,
 
135
                                             struct ucred **));
 
136
extern void nl_cb_overwrite_send(struct nl_cb *,
 
137
                                 int (*func)(struct nl_sock *,
 
138
                                             struct nl_msg *));
 
139
 
 
140
#ifdef __cplusplus
 
141
}
 
142
#endif
 
143
 
 
144
#endif