Port to libnl-3.x (Closes: #688166)
authorJoachim Breitner <mail@joachim-breitner.de>
Thu, 20 Sep 2012 08:14:08 +0000 (10:14 +0200)
committerJoachim Breitner <mail@joachim-breitner.de>
Thu, 20 Sep 2012 08:14:08 +0000 (10:14 +0200)
Makefile
debian/changelog
debian/control
libnss_gw_name.c

index 1c5b321..bb828a3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,9 +12,10 @@ SHARED_OBJECT = libnss_gw_name$(BITSOFS).so.2
 INSTALL_NAME = libnss_gw_name.so.2
 # This only works sometimes, give manually when needed:
 BIT_CFLAGS = $(if $(BITSOFS),-m$(BITSOFS))
-CFLAGS = $(BIT_CFLAGS) -g -O2 -Wall -Wpointer-arith
+CFLAGS = $(BIT_CFLAGS) -g -O2 -Wall -Wpointer-arith \
+       `pkg-config --cflags libnl-3.0 libnl-route-3.0`
 CPPFLAGS =
-LIBS = `pkg-config --libs libnl-1`
+LIBS = `pkg-config --libs libnl-3.0 libnl-route-3.0`
 LDFLAGS = -shared -Wl,-soname,$(INSTALL_NAME) -Wl,-z,defs
 
 all: $(SHARED_OBJECT)
index 199a287..eb3b389 100644 (file)
@@ -1,3 +1,9 @@
+libnss-gw-name (0.2.1-2) UNRELEASED; urgency=low
+
+  * Port to libnl-3.x (Closes: #688166)
+
+ -- Joachim Breitner <nomeata@debian.org>  Thu, 20 Sep 2012 09:28:21 +0200
+
 libnss-gw-name (0.2.1-1) unstable; urgency=low
 
   * Fix typo in Homepage, thx to Tomas Pospisek for noticing (Closes: #574893)
index e0b1c45..17fe657 100644 (file)
@@ -5,7 +5,8 @@ Maintainer: Joachim Breitner <nomeata@debian.org>
 Build-Depends:
   debhelper (>= 8.1.3),
   pkg-config,
-  libnl-dev,
+  libnl-3-dev,
+  libnl-route-3-dev,
 Standards-Version: 3.8.4
 Homepage: http://www.joachim-breitner.de/projects#libnss-gw-name
 VCS-Git: git://git.nomeata.de/libnss-gw-name.git
index ad33ffa..bc26e8e 100644 (file)
@@ -1,5 +1,5 @@
 /*  
- *  Copyright © 2010 Joachim Breitner
+ *  Copyright © 2010,2012 Joachim Breitner
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -20,7 +20,8 @@
  */
 
 
-#include <netlink/route/rtnl.h>
+// #include <netlink/route/rtnl.h>
+#include <netlink/socket.h>
 #include <netlink/route/route.h>
 #include <nss.h>
 #include <netdb.h>
@@ -41,24 +42,23 @@ typedef struct {
 static struct nl_addr *
 find_gateway() {
        struct nl_cache* route_cache;
-       struct nl_handle *sock;
+       struct nl_sock *sock;
        struct nl_object *obj;
        struct nl_addr *gw = NULL;
        int err;
 
        // Allocate a new netlink socket
-       sock = nl_handle_alloc();
+       sock = nl_socket_alloc();
 
        err = nl_connect(sock, NETLINK_ROUTE);
        if (err) {
-               nl_handle_destroy(sock);
+               nl_socket_free(sock);
                return NULL;
        }
 
-       route_cache = rtnl_route_alloc_cache (sock);
-       if (!route_cache) {
+       if (rtnl_route_alloc_cache(sock, AF_INET, 0, &route_cache)) {
                nl_close(sock);
-               nl_handle_destroy(sock);
+               nl_socket_free(sock);
                return NULL;
        }
 
@@ -69,10 +69,13 @@ find_gateway() {
                if (rtnl_route_get_family(route) != AF_INET) continue;
 
                // Find a default route
-               if (rtnl_route_get_dst_len(route) != 0) continue;
+               if (nl_addr_get_prefixlen(rtnl_route_get_dst(route)) != 0) continue;
+
+               // Assert a next hop
+               if (rtnl_route_get_nnexthops(route) < 1) continue;
                
                // Found a gateway
-               struct nl_addr *gw_ = rtnl_route_get_gateway(route);
+               struct nl_addr *gw_ = rtnl_route_nh_get_gateway(rtnl_route_nexthop_n(route, 0));
                if (!gw_) continue;
 
                // Clone the address, as this one will be freed with the route cache (will it?)
@@ -92,7 +95,7 @@ find_gateway() {
        nl_close(sock);
 
        // Finally destroy the netlink handle
-       nl_handle_destroy(sock);
+       nl_socket_free(sock);
 
        return gw;
 }
@@ -125,7 +128,7 @@ enum nss_status _nss_gw_name_gethostbyname_r (
                        8 /* Alignment */
                        )  {   /* official name */
 
-                       nl_addr_destroy(gw);
+                       nl_addr_put(gw);
 
                        *errnop = ERANGE;
                        *h_errnop = NO_RECOVERY;
@@ -155,7 +158,7 @@ enum nss_status _nss_gw_name_gethostbyname_r (
                result->h_addr_list[0] = buffer + astart;
                result->h_addr_list[1] = NULL;
 
-               nl_addr_destroy(gw);
+               nl_addr_put(gw);
                return NSS_STATUS_SUCCESS;
        }{
                *errnop = EINVAL;