]> git.ipfire.org Git - people/ms/strongswan.git/commitdiff
Add a traffic selector constructor creating a TS directly from a CIDR string
authorMartin Willi <martin@revosec.ch>
Thu, 18 Oct 2012 08:52:42 +0000 (10:52 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 24 Oct 2012 11:25:02 +0000 (13:25 +0200)
src/libstrongswan/selectors/traffic_selector.c
src/libstrongswan/selectors/traffic_selector.h

index b19b962e60c9a2b4584179668985a072ecadd1cc..81f480a3da933f43056f902c1adf74148bc2d024 100644 (file)
@@ -815,6 +815,23 @@ traffic_selector_t *traffic_selector_create_from_string(
        return (&this->public);
 }
 
+/*
+ * see header
+ */
+traffic_selector_t *traffic_selector_create_from_cidr(char *string,
+                                                                       u_int8_t protocol, u_int16_t port)
+{
+       host_t *net;
+       int bits;
+
+       net = host_create_from_subnet(string, &bits);
+       if (net)
+       {
+               return traffic_selector_create_from_subnet(net, bits, protocol, port);
+       }
+       return NULL;
+}
+
 /*
  * see header
  */
index 7a81521e91268b4d104cf49fe71fde4a8ce38761..39b8879fd567dd9c1ffcf03dde165b866b24e5ab 100644 (file)
@@ -231,6 +231,19 @@ traffic_selector_t *traffic_selector_create_from_string(
                                                                        char *from_addr, u_int16_t from_port,
                                                                        char *to_addr, u_int16_t to_port);
 
+
+
+/**
+ * Create a traffic selector from a CIDR string.
+ *
+ * @param string               CIDR string, such as 10.1.0.0/16
+ * @param protocol             protocol for this ts, such as TCP or UDP
+ * @param port                 single port for this TS, 0 for any port
+ * @return                             traffic selector, NULL if string invalid
+ */
+traffic_selector_t *traffic_selector_create_from_cidr(char *string,
+                                                                       u_int8_t protocol, u_int16_t port);
+
 /**
  * Create a new traffic selector using data read from the net.
  *