nullppp.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * OpenConnect (SSL + DTLS) VPN client
  3. *
  4. * Copyright © 2020 David Woodhouse
  5. *
  6. * Author: David Woodhouse <dwmw2@infradead.org>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public License
  10. * version 2.1, as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. */
  17. #include <config.h>
  18. #include "openconnect-internal.h"
  19. #include "ppp.h"
  20. #include <unistd.h>
  21. #include <fcntl.h>
  22. #include <sys/types.h>
  23. #include <time.h>
  24. #include <string.h>
  25. #include <ctype.h>
  26. #include <errno.h>
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include <stdarg.h>
  30. int nullppp_obtain_cookie(struct openconnect_info *vpninfo)
  31. {
  32. if (!(vpninfo->cookie = strdup("")))
  33. return -ENOMEM;
  34. return 0;
  35. }
  36. int nullppp_connect(struct openconnect_info *vpninfo)
  37. {
  38. int ret;
  39. int ipv4, ipv6, hdlc;
  40. /* XX: cookie hack. Use -C hdlc,noipv4,noipv6,term on the
  41. * command line to set options. */
  42. hdlc = strstr(vpninfo->cookie, "hdlc") ? 1 : 0;
  43. ipv4 = strstr(vpninfo->cookie, "noipv4") ? 0 : 1;
  44. ipv6 = strstr(vpninfo->cookie, "noipv6") ? 0 : 1;
  45. /* Now establish the actual connection */
  46. ret = openconnect_open_https(vpninfo);
  47. if (ret)
  48. goto out;
  49. ret = openconnect_ppp_new(vpninfo,
  50. hdlc ? PPP_ENCAP_RFC1662_HDLC : PPP_ENCAP_RFC1661,
  51. ipv4, ipv6);
  52. if (!ret) {
  53. /* Trigger the first PPP negotiations and ensure the PPP state
  54. * is PPPS_ESTABLISH so that ppp_tcp_mainloop() knows we've started. */
  55. ppp_start_tcp_mainloop(vpninfo);
  56. }
  57. out:
  58. if (ret)
  59. openconnect_close_https(vpninfo, 0);
  60. else {
  61. monitor_fd_new(vpninfo, ssl);
  62. monitor_read_fd(vpninfo, ssl);
  63. monitor_except_fd(vpninfo, ssl);
  64. }
  65. return ret;
  66. }
  67. int nullppp_mainloop(struct openconnect_info *vpninfo, int *timeout, int readable)
  68. {
  69. if (vpninfo->ppp->ppp_state >= PPPS_NETWORK &&
  70. strstr(vpninfo->cookie, "term")) {
  71. vpninfo->got_cancel_cmd = 1;
  72. vpn_progress(vpninfo, PRG_ERR,
  73. _("Terminating because nullppp has reached network state.\n"));
  74. }
  75. return ppp_tcp_mainloop(vpninfo, timeout, readable);
  76. }