]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
cleanup state printing
authorDaniel Lenski <dlenski@gmail.com>
Mon, 11 May 2020 22:10:06 +0000 (15:10 -0700)
committerDaniel Lenski <dlenski@gmail.com>
Tue, 12 May 2020 21:31:23 +0000 (14:31 -0700)
Signed-off-by: Daniel Lenski <dlenski@gmail.com>
openconnect-internal.h
ppp.c

index 6d1b717b7c137797feb88a6608d709d297fb23d6..8a32480fe484f431b12c0f468f1f47b6f49dc202 100644 (file)
@@ -941,7 +941,6 @@ int f5_bye(struct openconnect_info *vpninfo, const char *reason);
 struct oc_ppp;
 void buf_append_ppphdlc(struct oc_text_buf *buf, const unsigned char *bytes, int len, uint32_t asyncmap);
 void buf_append_ppp_hdr(struct oc_text_buf *buf, struct oc_ppp *ppp, uint16_t proto, uint8_t code, uint8_t id);
-void ppp_print_state(struct openconnect_info *vpninfo);
 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);
diff --git a/ppp.c b/ppp.c
index 2f78834d1d9be675355e05e42f3db567848abfad..6d53c646ac0aebdff377f8b1f516c85efe52343d 100644 (file)
--- a/ppp.c
+++ b/ppp.c
@@ -123,6 +123,8 @@ struct oc_ppp {
        uint64_t in_ipv6_int_ident;
 };
 
+const char *encap_names[] = {"F5", "F5 HDLC"};
+
 struct oc_ppp *openconnect_ppp_new(int encap, int want_ipv4, int want_ipv6)
 {
        struct oc_ppp *ppp = calloc(sizeof(*ppp), 1);
@@ -138,6 +140,8 @@ struct oc_ppp *openconnect_ppp_new(int encap, int want_ipv4, int want_ipv6)
 
        case PPP_ENCAP_F5_HDLC:
                ppp->hdlc = 1;
+               break;
+
        default:
                /* XX: fail */
                break;
@@ -149,14 +153,14 @@ struct oc_ppp *openconnect_ppp_new(int encap, int want_ipv4, int want_ipv6)
        return ppp;
 }
 
-void ppp_print_state(struct openconnect_info *vpninfo)
+static void print_ppp_state(struct openconnect_info *vpninfo, int level)
 {
        struct oc_ppp *ppp = vpninfo->ppp;
 
-       vpn_progress(vpninfo, PRG_INFO, _("PPP state: %s (%d)\n  hdlc: %d\n"), ppps_names[ppp->ppp_state], ppp->ppp_state, ppp->hdlc);
-       vpn_progress(vpninfo, PRG_INFO, _("    in: asyncmap=0x%08x, lcp_opts=%d, lcp_magic=0x%08x, peer=%s\n"),
+       vpn_progress(vpninfo, level, _("Current PPP state: %s (encap %s):\n"), ppps_names[ppp->ppp_state], encap_names[ppp->encap-1]);
+       vpn_progress(vpninfo, level, _("    in: asyncmap=0x%08x, lcp_opts=%d, lcp_magic=0x%08x, peer=%s\n"),
                     ppp->in_asyncmap, ppp->in_lcp_opts, ppp->in_lcp_magic, inet_ntoa(ppp->in_peer_addr));
-       vpn_progress(vpninfo, PRG_INFO, _("   out: asyncmap=0x%08x, lcp_opts=%d, lcp_magic=0x%08x, peer=%s\n"),
+       vpn_progress(vpninfo, level, _("   out: asyncmap=0x%08x, lcp_opts=%d, lcp_magic=0x%08x, peer=%s\n"),
                     ppp->out_asyncmap, ppp->out_lcp_opts, ppp->out_lcp_magic, inet_ntoa(ppp->out_peer_addr));
 }
 
@@ -506,10 +510,12 @@ int ppp_mainloop(struct openconnect_info *vpninfo, int *timeout, int readable)
                vpninfo->quit_reason = "Unexpected state";
                return 1;
        }
-       if (last_state != ppp->ppp_state)
+       if (last_state != ppp->ppp_state) {
                vpn_progress(vpninfo, PRG_DEBUG,
-                            _("PPP state transition from %s (%d) to %s (%d)\n"),
-                            ppps_names[last_state], last_state, ppps_names[ppp->ppp_state], ppp->ppp_state);
+                            _("PPP state transition from %s to %s\n"),
+                            ppps_names[last_state], ppps_names[ppp->ppp_state]);
+               print_ppp_state(vpninfo, PRG_TRACE);
+       }
 
        /* FIXME: The poll() handling here is fairly simplistic. Actually,
           if the SSL connection stalls it could return a WANT_WRITE error
@@ -634,8 +640,8 @@ int ppp_mainloop(struct openconnect_info *vpninfo, int *timeout, int readable)
                case PPP_IP6:
                        if (ppp->ppp_state != PPPS_NETWORK) {
                                vpn_progress(vpninfo, PRG_ERR,
-                                            _("Unexpected IPv%d packet in PPP state %s (%d)."),
-                                            (proto == PPP_IP6 ? 6 : 4), ppps_names[ppp->ppp_state], ppp->ppp_state);
+                                            _("Unexpected IPv%d packet in PPP state %s."),
+                                            (proto == PPP_IP6 ? 6 : 4), ppps_names[ppp->ppp_state]);
                                dump_buf_hex(vpninfo, PRG_ERR, '<', pp, payload_len);
                        } else {
                                vpn_progress(vpninfo, PRG_TRACE,