Merge lp:~asac/ntrack/lp686554 into lp:ntrack

Proposed by Alexander Sack
Status: Merged
Merged at revision: 220
Proposed branch: lp:~asac/ntrack/lp686554
Merge into: lp:ntrack
Diff against target: 249 lines (+94/-51)
2 files modified
common/ntrack-libnl.c (+80/-49)
configure.ac (+14/-2)
To merge this branch: bzr merge lp:~asac/ntrack/lp686554
Reviewer Review Type Date Requested Status
Alexander Sack Approve
Review via email: mp+44158@code.launchpad.net

Description of the change

waiting for feedback from lp:686554

To post a comment you must log in.
Revision history for this message
Alexander Sack (asac) wrote :

merged

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'common/ntrack-libnl.c'
2--- common/ntrack-libnl.c 2010-12-19 02:10:10 +0000
3+++ common/ntrack-libnl.c 2010-12-19 02:29:34 +0000
4@@ -19,6 +19,9 @@
5 * You should have received a copy of the GNU Lesser General Public License
6 * along with ntrack. If not, see <http://www.gnu.org/licenses/>.
7 */
8+
9+#include "config.h"
10+
11 #include "ntrackmonitor.h"
12 #include "ntrack-arch.h"
13 #include "ntracklist.h"
14@@ -44,10 +47,49 @@
15 #define ROUTE_ATTR_GATEWAY 0x000800
16 #endif
17
18+#ifdef HAVE_LIBNL1
19+typedef struct nl_handle NTRACK_nl_handle;
20+
21+#define NL_CACHE_MNGR_ALLOC(handle,mngr_o) \
22+ mngr_o = nl_cache_mngr_alloc (handle, \
23+ NETLINK_ROUTE, \
24+ NL_AUTO_PROVIDE)
25+
26+#define NL_CACHE_MNGR_ADD(mngr,name,cache_o) \
27+ cache_o = nl_cache_mngr_add (mngr, \
28+ name, \
29+ 0)
30+#define NL_PRINT_ERROR(text,err) \
31+ printf ("%s/%s\n", text, nl_geterror())
32+
33+#define RTNL_ROUTE_GET_PRIO rtnl_route_get_prio
34+
35+#else /* HAVE_LIBNL1 */
36+#ifdef HAVE_LIBNL2
37+typedef struct nl_sock NTRACK_nl_handle;
38+
39+#define NL_CACHE_MNGR_ALLOC(handle,mngr_o) \
40+ nl_cache_mngr_alloc (handle, NETLINK_ROUTE, NL_AUTO_PROVIDE, &mngr_o)
41+
42+#define NL_CACHE_MNGR_ADD(mngr,name,cache_o) \
43+ nl_cache_mngr_add (mngr, \
44+ name, \
45+ 0, \
46+ &cache_o)
47+#define NL_PRINT_ERROR(text,err) \
48+ printf ("%s/%s\n", text, nl_geterror(err))
49+
50+#define RTNL_ROUTE_GET_PRIO rtnl_route_get_priority
51+
52+#else
53+#error no LIBNLx found
54+#endif /* HAVE_LIBNL2 */
55+#endif /* HAVE_LIBNL1 */
56+
57 struct _nl_info
58 {
59- struct nl_handle *handle;
60- struct nl_handle *smart_update_handle;
61+ NTRACK_nl_handle *handle;
62+ NTRACK_nl_handle *smart_update_handle;
63
64 struct nl_cache_mngr *update_cache_mngr;
65 struct nl_cache_mngr *smart_update_cache_mngr;
66@@ -102,9 +144,17 @@
67 arch->cb = callback;
68 arch->cb_user_data = user_data;
69
70+#ifdef HAVE_LIBNL1
71 nl_info->handle = nl_handle_alloc();
72 nl_info->smart_update_handle = nl_handle_alloc();
73-
74+#else
75+#ifdef HAVE_LIBNL2
76+ nl_info->handle = nl_socket_alloc();
77+ nl_info->smart_update_handle = nl_socket_alloc();
78+#else
79+#error "needs libnl-1 or -2.0"
80+#endif
81+#endif
82 if (!nl_info->handle)
83 error (1, 255, "OOM (nl_handle_alloc)");
84
85@@ -185,40 +235,22 @@
86 static void
87 setup_main_handle (struct _nl_info *nl_info)
88 {
89- nl_info->update_cache_mngr =
90- nl_cache_mngr_alloc(nl_info->handle,
91- NETLINK_ROUTE,
92- NL_AUTO_PROVIDE);
93+ NL_CACHE_MNGR_ALLOC (nl_info->handle, nl_info->update_cache_mngr);
94
95 if (!nl_info->addr_cache) {
96- nl_info->addr_cache = nl_cache_mngr_add (nl_info->update_cache_mngr,
97- "route/addr",
98- NULL /* change_func_t -
99- we dont want those
100- notifications */
101- );
102+ NL_CACHE_MNGR_ADD (nl_info->update_cache_mngr, "route/addr", nl_info->addr_cache);
103 if (!nl_info->addr_cache)
104 error (1, 366, "cache mngr add fail.");
105 }
106
107 if (!nl_info->link_cache) {
108- nl_info->link_cache = nl_cache_mngr_add (nl_info->update_cache_mngr,
109- "route/link",
110- NULL /* change_func_t -
111- we dont want those
112- notifications */
113- );
114+ NL_CACHE_MNGR_ADD (nl_info->update_cache_mngr, "route/link", nl_info->link_cache);
115 if (!nl_info->link_cache)
116 error (1, 367, "cache mngr add fail.");
117 }
118
119 if (!nl_info->route_cache) {
120- nl_info->route_cache = nl_cache_mngr_add (nl_info->update_cache_mngr,
121- "route/route",
122- NULL /* change_func_t -
123- we dont want those
124- notifications */
125- );
126+ NL_CACHE_MNGR_ADD (nl_info->update_cache_mngr, "route/route", nl_info->route_cache);
127 if (!nl_info->route_cache)
128 error (1, 368, "cache mngr add fail.");
129 }
130@@ -228,10 +260,7 @@
131 setup_smart_handle (struct _nl_info *nl_info)
132 {
133 struct nl_cache *tmp_cache = 0;
134- nl_info->smart_update_cache_mngr =
135- nl_cache_mngr_alloc(nl_info->smart_update_handle,
136- NETLINK_ROUTE,
137- NL_AUTO_PROVIDE);
138+ NL_CACHE_MNGR_ALLOC (nl_info->smart_update_handle, nl_info->smart_update_cache_mngr);
139
140 if (!nl_info->smart_update_cache_mngr)
141 error (1, 265, "cache mngr alloc failed");
142@@ -243,34 +272,20 @@
143 * explicitly refill the primary caches and calculate
144 * network status changes.
145 */
146- tmp_cache = nl_cache_mngr_add (nl_info->smart_update_cache_mngr,
147- "route/addr",
148- NULL /* change_func_t -
149- we dont want those
150- notifications */
151- );
152+
153+ NL_CACHE_MNGR_ADD (nl_info->smart_update_cache_mngr, "route/addr", tmp_cache);
154
155 if (!tmp_cache)
156 error (1, 266, "cache mngr add fail.");
157
158 tmp_cache = 0;
159- tmp_cache = nl_cache_mngr_add (nl_info->smart_update_cache_mngr,
160- "route/link",
161- NULL /* change_func_t -
162- we dont want those
163- notifications */
164- );
165+ NL_CACHE_MNGR_ADD (nl_info->smart_update_cache_mngr, "route/link", tmp_cache);
166
167 if (!tmp_cache)
168 error (1, 267, "cache mngr add fail.");
169
170 tmp_cache = 0;
171- tmp_cache = nl_cache_mngr_add (nl_info->smart_update_cache_mngr,
172- "route/route",
173- NULL /* change_func_t -
174- we dont want those
175- notifications */
176- );
177+ NL_CACHE_MNGR_ADD (nl_info->smart_update_cache_mngr, "route/route", tmp_cache);
178
179 if (!tmp_cache)
180 error (1, 268, "cache mngr add fail.");
181@@ -310,8 +325,8 @@
182 if (first_route == NULL || second_route == NULL)
183 return 0;
184
185- metric1 = rtnl_route_get_prio (first_route);
186- metric2 = rtnl_route_get_prio (second_route);
187+ metric1 = RTNL_ROUTE_GET_PRIO (first_route);
188+ metric2 = RTNL_ROUTE_GET_PRIO (second_route);
189
190 if (metric1 < metric2)
191 return -1;
192@@ -400,10 +415,26 @@
193 iter = nl_cache_get_first (nl_info->route_cache);
194 while (iter) {
195 struct rtnl_link *iter_link;
196+#ifdef HAVE_LIBNL2
197+ struct rtnl_nexthop *nexth=0;
198+ int nhops=0;
199+#endif
200 if (!nl_object_match_filter (iter, OBJ_CAST(filter_route)))
201 goto next;
202
203+#ifdef HAVE_LIBNL2
204+ nhops = rtnl_route_get_nnexthops ((struct rtnl_route*) iter);
205+ if (nhops > 0)
206+ nexth = rtnl_route_nexthop_n ((struct rtnl_route*) iter, 0);
207+
208+ iter_link = get_nl_link_by_index (self, link_list, rtnl_route_nh_get_ifindex (nexth));
209+#else
210+#ifdef HAVE_LIBNL1
211 iter_link = get_nl_link_by_index (self, link_list, rtnl_route_get_oif ((struct rtnl_route*) iter));
212+#else
213+#error "no libnl"
214+#endif
215+#endif
216
217 /* if we dont have a link for the current oif,
218 * this is not a valid topmost_route */
219
220=== modified file 'configure.ac'
221--- configure.ac 2010-10-10 20:48:09 +0000
222+++ configure.ac 2010-12-19 02:29:34 +0000
223@@ -111,13 +111,25 @@
224
225 AM_CONDITIONAL(HAVE_QT4, test $ac_have_qt4 = 1)
226
227-PKG_CHECK_MODULES(LIBNL, libnl-1, ac_have_libnl=1,ac_have_libnl=0)
228+PKG_CHECK_MODULES(LIBNL, libnl-2.0, ac_have_libnl=1,ac_have_libnl=0)
229 AC_SUBST(LIBNL_CFLAGS)
230 AC_SUBST(LIBNL_LIBS)
231 AM_CONDITIONAL(HAVE_LIBNL, test $ac_have_libnl = 1)
232
233+if test $ac_have_libnl = 1; then
234+ AC_DEFINE([HAVE_LIBNL2], [], [HAVE_LIBNL1])
235+else
236+ PKG_CHECK_MODULES(LIBNL, libnl-1, ac_have_libnl=1,ac_have_libnl=0)
237+ AC_SUBST(LIBNL_CFLAGS)
238+ AC_SUBST(LIBNL_LIBS)
239+ AM_CONDITIONAL(HAVE_LIBNL, test $ac_have_libnl = 1)
240+ if test $ac_have_libnl = 1; then
241+ AC_DEFINE([HAVE_LIBNL1], [], [HAVE_LIBNL1])
242+ fi
243+fi
244+
245 # consistency checks
246-if ! test "$ac_have_libnl" = "1"; then
247+if ! test "$ac_have_libnl" = "1" -o "$ac_have_libnl2" = 1; then
248 AC_ERROR([libnl is required])
249 fi
250

Subscribers

People subscribed via source and target branches

to all changes: