ppp.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * OpenConnect (SSL + DTLS) VPN client
  3. *
  4. * Copyright © 2020 David Woodhouse, Daniel Lenski
  5. *
  6. * Authors: David Woodhouse <dwmw2@infradead.org>, Daniel Lenski <dlenski@gmail.com>
  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. #ifndef __OPENCONNECT_PPP_H__
  18. #define __OPENCONNECT_PPP_H__
  19. /* PPP protocol field values */
  20. #define PPP_LCP 0xc021
  21. #define PPP_IPCP 0x8021
  22. #define PPP_IP6CP 0x8057
  23. #define PPP_CCP 0x80fd /* compression (unwanted) */
  24. #define PPP_IP 0x21
  25. #define PPP_IP6 0x57
  26. /* NCP packet formats (https://tools.ietf.org/html/rfc1661#section-3.2) */
  27. #define CONFREQ 1
  28. #define CONFACK 2
  29. #define CONFNAK 3
  30. #define CONFREJ 4
  31. #define TERMREQ 5
  32. #define TERMACK 6
  33. #define CODEREJ 7
  34. #define PROTREJ 8
  35. #define ECHOREQ 9
  36. #define ECHOREP 10
  37. #define DISCREQ 11
  38. /* HDLC (https://tools.ietf.org/html/rfc1662) */
  39. #define PPPINITFCS16 0xffff /* Initial FCS value */
  40. #define PPPGOODFCS16 0xf0b8 /* Good final FCS value */
  41. #define ASYNCMAP_LCP 0xffffffffUL /* When sending LCP, always escape characters < 0x20 */
  42. /* PPP states (https://tools.ietf.org/html/rfc1661#section-3.2) */
  43. #define PPPS_DEAD 0
  44. #define PPPS_ESTABLISH 1
  45. #define PPPS_OPENED 2
  46. #define PPPS_AUTHENTICATE 3
  47. #define PPPS_NETWORK 4
  48. #define PPPS_TERMINATE 5
  49. /* NCP states */
  50. #define NCP_CONF_REQ_RECEIVED 1
  51. #define NCP_CONF_REQ_SENT 2
  52. #define NCP_CONF_ACK_RECEIVED 4
  53. #define NCP_CONF_ACK_SENT 8
  54. #define NCP_TERM_REQ_SENT 16
  55. #define NCP_TERM_REQ_RECEIVED 32
  56. #define NCP_TERM_ACK_SENT 64
  57. #define NCP_TERM_ACK_RECEIVED 128
  58. /* RFC1661 (or RFC1662 for ASYNCMAP) */
  59. #define LCP_MRU 1
  60. #define LCP_ASYNCMAP 2
  61. #define LCP_MAGIC 5
  62. #define LCP_PFCOMP 7
  63. #define LCP_ACCOMP 8
  64. #define BIT_MRU (1 << LCP_MRU)
  65. #define BIT_ASYNCMAP (1 << LCP_ASYNCMAP)
  66. #define BIT_MAGIC (1 << LCP_MAGIC)
  67. #define BIT_PFCOMP (1 << LCP_PFCOMP)
  68. #define BIT_ACCOMP (1 << LCP_ACCOMP)
  69. #define BIT_MRU_COAX (1 << 9)
  70. /* RFC1332 */
  71. #define IPCP_IPADDRS 1
  72. #define IPCP_IPCOMP 2
  73. #define IPCP_IPADDR 3
  74. /* RFC1877: DNS[0]=129, NBNS[0]=130, DNS[1]=131, NBNS[1]=132 */
  75. #define IPCP_xNS_BASE 129
  76. #define IPCP_DNS0 1
  77. #define IPCP_NBNS0 2
  78. #define IPCP_DNS1 4
  79. #define IPCP_NBNS1 8
  80. /* RFC5072 */
  81. #define IP6CP_INT_ID 1
  82. struct oc_ncp {
  83. int state;
  84. int id;
  85. int termreqs_sent;
  86. time_t last_req;
  87. };
  88. struct oc_ppp {
  89. /* We need to know these before we start */
  90. int encap;
  91. int encap_len;
  92. int hdlc;
  93. int want_ipv4;
  94. int want_ipv6;
  95. int check_http_response;
  96. int terminate_on_pause;
  97. int ppp_state;
  98. struct oc_ncp lcp;
  99. struct oc_ncp ipcp;
  100. struct oc_ncp ip6cp;
  101. /* Outgoing options */
  102. uint32_t out_asyncmap;
  103. int out_lcp_opts;
  104. int32_t out_lcp_magic; /* stored in on-the-wire order */
  105. struct in_addr out_ipv4_addr;
  106. struct in6_addr out_ipv6_addr;
  107. int solicit_peerns; /* bitfield of DNS/NBNS to request */
  108. int got_peerns;
  109. /* Incoming options */
  110. uint32_t in_asyncmap;
  111. int in_lcp_opts;
  112. int32_t in_lcp_magic; /* stored in on-the-wire order */
  113. struct in_addr in_ipv4_addr;
  114. struct in6_addr in_ipv6_addr;
  115. struct in_addr nameservers[4];
  116. int exp_ppp_hdr_size; /* predicted size of next PPP header */
  117. };
  118. #endif /* __OPENCONNECT_PPP_H__ */