]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
curl: add an option to fetch bound to a local source address
authorMartin Willi <martin@revosec.ch>
Wed, 15 May 2013 14:34:12 +0000 (16:34 +0200)
committerMartin Willi <martin@revosec.ch>
Tue, 11 Jun 2013 13:54:26 +0000 (15:54 +0200)
src/libstrongswan/fetcher/fetcher.h
src/libstrongswan/fetcher/fetcher_manager.c
src/libstrongswan/plugins/curl/curl_fetcher.c

index 58451aef2309b1f67d03d36c9be304af7a04d9e0..890258c3caa19d108302dc80e1765c83014e09a8 100644 (file)
@@ -89,6 +89,12 @@ enum fetcher_option_t {
         */
        FETCH_CALLBACK,
 
+       /**
+        * Source IP address to bind for a fetch.
+        * Additional argument is a host_t*, which may be NULL.
+        */
+       FETCH_SOURCEIP,
+
        /**
         * end of fetching options
         */
index 47d4f9bdedaebcaa778e95f72415d205dcad96e7..21cd1aff451d0f6f221a52b81ac404af2857b204 100644 (file)
@@ -73,6 +73,7 @@ METHOD(fetcher_manager_t, fetch, status_t,
                fetcher_option_t opt;
                fetcher_t *fetcher;
                bool good = TRUE;
+               host_t *host;
                va_list args;
 
                /* check URL support of fetcher */
@@ -112,6 +113,13 @@ METHOD(fetcher_manager_t, fetch, status_t,
                                        good = fetcher->set_option(fetcher, opt,
                                                                                        va_arg(args, fetcher_callback_t));
                                        continue;
+                               case FETCH_SOURCEIP:
+                                       host = va_arg(args, host_t*);
+                                       if (host && !host->is_anyaddr(host))
+                                       {
+                                               good = fetcher->set_option(fetcher, opt, host);
+                                       }
+                                       continue;
                                case FETCH_END:
                                        break;
                        }
index b49961a90b571a170fab48009755aa74348d54e7..a8cca98daac58b283af4c71de60760baf63912bd 100644 (file)
@@ -177,6 +177,15 @@ METHOD(fetcher_t, set_option, bool,
                        this->cb = va_arg(args, fetcher_callback_t);
                        break;
                }
+               case FETCH_SOURCEIP:
+               {
+                       char buf[64];
+
+                       snprintf(buf, sizeof(buf), "%H", va_arg(args, host_t*));
+                       supported = curl_easy_setopt(this->curl, CURLOPT_INTERFACE,
+                                                                                buf) == CURLE_OK;
+                       break;
+               }
                default:
                        supported = FALSE;
                        break;