]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
create vpninfo->ppp in-place
authorDaniel Lenski <dlenski@gmail.com>
Sat, 16 May 2020 00:54:41 +0000 (17:54 -0700)
committerDaniel Lenski <dlenski@gmail.com>
Sat, 16 May 2020 01:52:48 +0000 (18:52 -0700)
Signed-off-by: Daniel Lenski <dlenski@gmail.com>
f5.c
fortinet.c
nx.c
openconnect-internal.h
ppp.c

diff --git a/f5.c b/f5.c
index 2f1aa0bb232a4b99134b1487a79ce3a99b1a5f59..81ff47b69b1fdfa62f23448f55ed8d470f598c79 100644 (file)
--- a/f5.c
+++ b/f5.c
@@ -410,14 +410,8 @@ int f5_connect(struct openconnect_info *vpninfo)
                goto out;
        }
 
-       vpninfo->ppp = openconnect_ppp_new(hdlc ? PPP_ENCAP_F5_HDLC : PPP_ENCAP_F5,
-                                          ipv4, ipv6);
-       if (!vpninfo->ppp) {
-               ret = -ENOMEM;
-               goto out;
-       }
+       ret = openconnect_ppp_new(vpninfo, hdlc ? PPP_ENCAP_F5_HDLC : PPP_ENCAP_F5, ipv4, ipv6);
 
-       ret = 0; /* success */
  out:
        free(profile_params);
        free(sid);
index 3831edc76dec527c442402b88fc423b339d9b5e8..79ca38ec9f20313cb08cb222977fbd1eb0511dc0 100644 (file)
@@ -312,13 +312,8 @@ int fortinet_connect(struct openconnect_info *vpninfo)
                goto out;
        }
 
-       vpninfo->ppp = openconnect_ppp_new(PPP_ENCAP_FORTINET_HDLC, ipv4, ipv6);
-       if (!vpninfo->ppp) {
-               ret = -ENOMEM;
-               goto out;
-       }
+       ret = openconnect_ppp_new(vpninfo, PPP_ENCAP_FORTINET_HDLC, ipv4, ipv6);
 
-       ret = 0; /* success */
  out:
        if (ret)
                openconnect_close_https(vpninfo, 0);
diff --git a/nx.c b/nx.c
index d9789b68bdf2420bf12fe30cd19b2483ae147071..43f752b94d07494a0c54b980d25b960c48888bc0 100644 (file)
--- a/nx.c
+++ b/nx.c
@@ -93,13 +93,7 @@ int nx_connect(struct openconnect_info *vpninfo)
        // first byte as an indicator of success and don't need to check for "HTTP"
        // TODO: actually handle errors as described above
        vpn_progress(vpninfo, PRG_DEBUG, _("Connection established\n"));
-       vpninfo->ppp = openconnect_ppp_new(PPP_ENCAP_NX_HDLC, ipv4, ipv6);
-       if (!vpninfo->ppp) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       ret = 0;
+       ret = openconnect_ppp_new(vpninfo, PPP_ENCAP_NX_HDLC, ipv4, ipv6);
 
 out:
        if (ret < 0)
@@ -120,4 +114,4 @@ int nx_bye(struct openconnect_info *vpninfo, const char *reason)
        //ppp_bye(vpninfo);
        // TODO: implement
        return -EINVAL;
-}
\ No newline at end of file
+}
index dbf57b59af8fe9e5ed522fc8da780255e7178dab..e028d8d5e1168856b273914d8a4120f84ee24c87 100644 (file)
@@ -958,7 +958,7 @@ void buf_append_ppphdlc(struct oc_text_buf *buf, const unsigned char *bytes, int
 void buf_append_ppp_hdr(struct oc_text_buf *buf, struct oc_ppp *ppp, uint16_t proto, uint8_t code, uint8_t id);
 int ppp_negotiate_config(struct openconnect_info *vpninfo);
 int ppp_mainloop(struct openconnect_info *vpninfo, int *timeout, int readable);
-struct oc_ppp *openconnect_ppp_new(int encap, int want_ipv4, int want_ipv6);
+int openconnect_ppp_new(struct openconnect_info *vpninfo, int encap, int want_ipv4, int want_ipv6);
 
 /* auth-globalprotect.c */
 int gpst_obtain_cookie(struct openconnect_info *vpninfo);
diff --git a/ppp.c b/ppp.c
index ff28d4c5d3d2bd03ae43e68024b0ab17de848fd4..b898c9a2677390a49a012eafc1e76b499c4dd578 100644 (file)
--- a/ppp.c
+++ b/ppp.c
@@ -189,12 +189,13 @@ static const char *lcp_names[] = {
        "Discard-Request",
 };
 
-struct oc_ppp *openconnect_ppp_new(int encap, int want_ipv4, int want_ipv6)
+int openconnect_ppp_new(struct openconnect_info *vpninfo,
+                       int encap, int want_ipv4, int want_ipv6)
 {
-       struct oc_ppp *ppp = calloc(sizeof(*ppp), 1);
+       struct oc_ppp *ppp = vpninfo->ppp = calloc(sizeof(*ppp), 1);
 
        if (!ppp)
-               return NULL;
+               return -ENOMEM;
 
        ppp->encap = encap;
        switch (encap) {
@@ -215,7 +216,7 @@ struct oc_ppp *openconnect_ppp_new(int encap, int want_ipv4, int want_ipv6)
 
        default:
                free(ppp);
-               return NULL;
+               return -EINVAL;
        }
 
        ppp->want_ipv4 = want_ipv4;
@@ -227,10 +228,10 @@ struct oc_ppp *openconnect_ppp_new(int encap, int want_ipv4, int want_ipv6)
 
        if (openconnect_random(&ppp->out_lcp_magic, sizeof(ppp->out_lcp_magic))) {
                free(ppp);
-               return NULL;
+               return -EINVAL;
        }
 
-       return ppp;
+       return 0;
 }
 
 static void print_ppp_state(struct openconnect_info *vpninfo, int level)