]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
tun_device: add a getter for the address previously passed to set_address()
authorMartin Willi <martin@revosec.ch>
Fri, 12 Apr 2013 11:03:21 +0000 (13:03 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 6 May 2013 14:10:11 +0000 (16:10 +0200)
src/libstrongswan/networking/tun_device.c
src/libstrongswan/networking/tun_device.h

index b0be8688e628de564959ff33a9281eb2d0c222f6..2191198e2927d69ad6fa1833cf689311af0f5fe2 100644 (file)
@@ -73,6 +73,16 @@ struct private_tun_device_t {
         * The current MTU
         */
        int mtu;
+
+       /**
+        * Associated address
+        */
+       host_t *address;
+
+       /**
+        * Netmask for address
+        */
+       u_int8_t netmask;
 };
 
 METHOD(tun_device_t, set_address, bool,
@@ -117,9 +127,21 @@ METHOD(tun_device_t, set_address, bool,
                         this->if_name, strerror(errno));
                return FALSE;
        }
+       this->address = addr->clone(addr);
+       this->netmask = netmask;
        return TRUE;
 }
 
+METHOD(tun_device_t, get_address, host_t*,
+       private_tun_device_t *this, u_int8_t *netmask)
+{
+       if (netmask && this->address)
+       {
+               *netmask = this->netmask;
+       }
+       return this->address;
+}
+
 METHOD(tun_device_t, up, bool,
        private_tun_device_t *this)
 {
@@ -277,6 +299,7 @@ METHOD(tun_device_t, destroy, void,
        {
                close(this->sock);
        }
+       DESTROY_IF(this->address);
        free(this);
 }
 
@@ -406,6 +429,7 @@ tun_device_t *tun_device_create(const char *name_tmpl)
                        .get_name = _get_name,
                        .get_fd = _get_fd,
                        .set_address = _set_address,
+                       .get_address = _get_address,
                        .up = _up,
                        .destroy = _destroy,
                },
index 3bdb02a5d3facf12f6f69b2d18ab8cd50fcd9c56..1d330f133a0c5e2186bbeb38493bbfce06b2e4c6 100644 (file)
@@ -65,6 +65,14 @@ struct tun_device_t {
         */
        bool (*set_address)(tun_device_t *this, host_t *addr, u_int8_t netmask);
 
+       /**
+        * Get the IP address previously assigned to using set_address().
+        *
+        * @param netmask               pointer receiving the configured netmask, or NULL
+        * @return                              address previously set, NULL if none
+        */
+       host_t* (*get_address)(tun_device_t *this, u_int8_t *netmask);
+
        /**
         * Bring the TUN device up
         *