44 #if PPP_SUPPORT && PPP_IPV4_SUPPORT 55 #include <sys/param.h> 56 #include <sys/types.h> 58 #include <netinet/in.h> 59 #include <arpa/inet.h> 73 bool disable_defaultip = 0;
82 void (*ip_up_hook) (void) =
NULL;
85 void (*ip_down_hook) (void) =
NULL;
93 struct notifier *ip_up_notifier =
NULL;
94 struct notifier *ip_down_notifier =
NULL;
99 static int default_route_set[NUM_PPP];
100 static int proxy_arp_set[NUM_PPP];
101 static int ipcp_is_up;
102 static int ipcp_is_open;
103 static bool ask_for_local;
106 static char vj_value[8];
107 static char netmask_str[20];
113 static void ipcp_resetci(fsm *f);
114 static int ipcp_cilen(fsm *f);
115 static void ipcp_addci(fsm *f, u_char *ucp,
int *lenp);
116 static int ipcp_ackci(fsm *f, u_char *p,
int len);
117 static int ipcp_nakci(fsm *f, u_char *p,
int len,
int treat_as_reject);
118 static int ipcp_rejci(fsm *f, u_char *p,
int len);
119 static int ipcp_reqci(fsm *f, u_char *inp,
int *len,
int reject_if_disagree);
120 static void ipcp_up(fsm *f);
121 static void ipcp_down(fsm *f);
122 static void ipcp_finished(fsm *f);
124 static const fsm_callbacks ipcp_callbacks = {
146 static int setvjslots (
char **);
147 static int setdnsaddr (
char **);
148 static int setwinsaddr (
char **);
149 static int setnetmask (
char **);
150 int setipaddr (
char *,
char **,
int);
152 static void printipaddr (option_t *,
void (*)(
void *,
char *,...),
void *);
154 static option_t ipcp_option_list[] = {
155 {
"noip", o_bool, &ipcp_protent.enabled_flag,
156 "Disable IP and IPCP" },
157 {
"-ip", o_bool, &ipcp_protent.enabled_flag,
158 "Disable IP and IPCP", OPT_ALIAS },
160 {
"novj", o_bool, &ipcp_wantoptions[0].neg_vj,
161 "Disable VJ compression", OPT_A2CLR, &ipcp_allowoptions[0].neg_vj },
162 {
"-vj", o_bool, &ipcp_wantoptions[0].neg_vj,
163 "Disable VJ compression", OPT_ALIAS | OPT_A2CLR,
164 &ipcp_allowoptions[0].neg_vj },
166 {
"novjccomp", o_bool, &ipcp_wantoptions[0].cflag,
167 "Disable VJ connection-ID compression", OPT_A2CLR,
168 &ipcp_allowoptions[0].cflag },
169 {
"-vjccomp", o_bool, &ipcp_wantoptions[0].cflag,
170 "Disable VJ connection-ID compression", OPT_ALIAS | OPT_A2CLR,
171 &ipcp_allowoptions[0].cflag },
173 {
"vj-max-slots", o_special, (
void *)setvjslots,
174 "Set maximum VJ header slots",
175 OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, vj_value },
177 {
"ipcp-accept-local", o_bool, &ipcp_wantoptions[0].accept_local,
178 "Accept peer's address for us", 1 },
179 {
"ipcp-accept-remote", o_bool, &ipcp_wantoptions[0].accept_remote,
180 "Accept peer's address for it", 1 },
182 {
"ipparam", o_string, &ipparam,
183 "Set ip script parameter", OPT_PRIO },
185 {
"noipdefault", o_bool, &disable_defaultip,
186 "Don't use name for default IP adrs", 1 },
188 {
"ms-dns", 1, (
void *)setdnsaddr,
189 "DNS address for the peer's use" },
190 {
"ms-wins", 1, (
void *)setwinsaddr,
191 "Nameserver for SMB over TCP/IP for peer" },
193 {
"ipcp-restart", o_int, &ipcp_fsm[0].timeouttime,
194 "Set timeout for IPCP", OPT_PRIO },
195 {
"ipcp-max-terminate", o_int, &ipcp_fsm[0].maxtermtransmits,
196 "Set max #xmits for term-reqs", OPT_PRIO },
197 {
"ipcp-max-configure", o_int, &ipcp_fsm[0].maxconfreqtransmits,
198 "Set max #xmits for conf-reqs", OPT_PRIO },
199 {
"ipcp-max-failure", o_int, &ipcp_fsm[0].maxnakloops,
200 "Set max #conf-naks for IPCP", OPT_PRIO },
202 {
"defaultroute", o_bool, &ipcp_wantoptions[0].default_route,
203 "Add default route", OPT_ENABLE|1, &ipcp_allowoptions[0].default_route },
204 {
"nodefaultroute", o_bool, &ipcp_allowoptions[0].default_route,
205 "disable defaultroute option", OPT_A2CLR,
206 &ipcp_wantoptions[0].default_route },
207 {
"-defaultroute", o_bool, &ipcp_allowoptions[0].default_route,
208 "disable defaultroute option", OPT_ALIAS | OPT_A2CLR,
209 &ipcp_wantoptions[0].default_route },
211 {
"replacedefaultroute", o_bool,
212 &ipcp_wantoptions[0].replace_default_route,
213 "Replace default route", 1
215 {
"noreplacedefaultroute", o_bool,
216 &ipcp_allowoptions[0].replace_default_route,
217 "Never replace default route", OPT_A2COPY,
218 &ipcp_wantoptions[0].replace_default_route },
219 {
"proxyarp", o_bool, &ipcp_wantoptions[0].proxy_arp,
220 "Add proxy ARP entry", OPT_ENABLE|1, &ipcp_allowoptions[0].proxy_arp },
221 {
"noproxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
222 "disable proxyarp option", OPT_A2CLR,
223 &ipcp_wantoptions[0].proxy_arp },
224 {
"-proxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
225 "disable proxyarp option", OPT_ALIAS | OPT_A2CLR,
226 &ipcp_wantoptions[0].proxy_arp },
228 {
"usepeerdns", o_bool, &usepeerdns,
229 "Ask peer for DNS address(es)", 1 },
231 {
"netmask", o_special, (
void *)setnetmask,
232 "set netmask", OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, netmask_str },
234 {
"ipcp-no-addresses", o_bool, &ipcp_wantoptions[0].old_addrs,
235 "Disable old-style IP-Addresses usage", OPT_A2CLR,
236 &ipcp_allowoptions[0].old_addrs },
237 {
"ipcp-no-address", o_bool, &ipcp_wantoptions[0].neg_addr,
238 "Disable IP-Address usage", OPT_A2CLR,
239 &ipcp_allowoptions[0].neg_addr },
241 {
"noremoteip", o_bool, &noremoteip,
242 "Allow peer to have no IP address", 1 },
244 {
"nosendip", o_bool, &ipcp_wantoptions[0].neg_addr,
245 "Don't send our IP address to peer", OPT_A2CLR,
246 &ipcp_wantoptions[0].old_addrs},
248 {
"IP addresses", o_wild, (
void *) &setipaddr,
249 "set local and remote IP addresses",
250 OPT_NOARG | OPT_A2PRINTER, (
void *) &printipaddr },
259 static void ipcp_init(ppp_pcb *pcb);
260 static void ipcp_open(ppp_pcb *pcb);
261 static void ipcp_close(ppp_pcb *pcb,
const char *reason);
262 static void ipcp_lowerup(ppp_pcb *pcb);
263 static void ipcp_lowerdown(ppp_pcb *pcb);
264 static void ipcp_input(ppp_pcb *pcb, u_char *p,
int len);
265 static void ipcp_protrej(ppp_pcb *pcb);
267 static int ipcp_printpkt(
const u_char *p,
int plen,
268 void (*printer) (
void *,
const char *, ...),
void *arg);
271 static void ip_check_options (
void);
274 static int ip_demand_conf (
int);
275 static int ip_active_pkt (u_char *,
int);
281 const struct protent ipcp_protent = {
310 static void ipcp_clear_addrs(ppp_pcb *pcb,
u32_t ouraddr,
u32_t hisaddr,
u8_t replacedefaultroute);
316 #define CILEN_COMPRESS 4 319 #define CILEN_ADDRS 10 322 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \ 323 (x) == CONFNAK ? "NAK" : "REJ") 335 slprintf(b,
sizeof(b),
"%I", ipaddr);
355 if (!int_option(*argv, &value))
359 if (value < 2 || value > 16) {
360 option_error(
"vj-max-slots value must be between 2 and 16");
363 ipcp_wantoptions [0].maxslotindex =
364 ipcp_allowoptions[0].maxslotindex = value - 1;
365 slprintf(vj_value,
sizeof(vj_value),
"%d", value);
379 dns = inet_addr(*argv);
380 if (dns == (
u32_t) -1) {
381 if ((hp = gethostbyname(*argv)) ==
NULL) {
382 option_error(
"invalid address parameter '%s' for ms-dns option",
386 dns = *(
u32_t *)hp->h_addr;
392 if (ipcp_allowoptions[0].dnsaddr[1] == 0)
393 ipcp_allowoptions[0].dnsaddr[0] = dns;
395 ipcp_allowoptions[0].dnsaddr[0] = ipcp_allowoptions[0].dnsaddr[1];
398 ipcp_allowoptions[0].dnsaddr[1] = dns;
415 wins = inet_addr(*argv);
416 if (wins == (
u32_t) -1) {
417 if ((hp = gethostbyname(*argv)) ==
NULL) {
418 option_error(
"invalid address parameter '%s' for ms-wins option",
422 wins = *(
u32_t *)hp->h_addr;
428 if (ipcp_allowoptions[0].winsaddr[1] == 0)
429 ipcp_allowoptions[0].winsaddr[0] = wins;
431 ipcp_allowoptions[0].winsaddr[0] = ipcp_allowoptions[0].winsaddr[1];
434 ipcp_allowoptions[0].winsaddr[1] = wins;
446 setipaddr(arg, argv, doit)
454 ipcp_options *wo = &ipcp_wantoptions[0];
455 static int prio_local = 0, prio_remote = 0;
460 if ((colon = strchr(arg,
':')) ==
NULL)
468 if (colon != arg && option_priority >= prio_local) {
470 if ((local = inet_addr(arg)) == (
u32_t) -1) {
471 if ((hp = gethostbyname(arg)) ==
NULL) {
472 option_error(
"unknown host: %s", arg);
475 local = *(
u32_t *)hp->h_addr;
477 if (bad_ip_adrs(local)) {
478 option_error(
"bad local IP address %s", ip_ntoa(local));
484 prio_local = option_priority;
490 if (*++colon !=
'\0' && option_priority >= prio_remote) {
491 if ((remote = inet_addr(colon)) == (
u32_t) -1) {
492 if ((hp = gethostbyname(colon)) ==
NULL) {
493 option_error(
"unknown host: %s", colon);
496 remote = *(
u32_t *)hp->h_addr;
497 if (remote_name[0] == 0)
498 strlcpy(remote_name, colon,
sizeof(remote_name));
500 if (bad_ip_adrs(remote)) {
501 option_error(
"bad remote IP address %s", ip_ntoa(remote));
505 wo->hisaddr = remote;
506 prio_remote = option_priority;
513 printipaddr(opt, printer, arg)
515 void (*printer) (
void *,
char *, ...);
518 ipcp_options *wo = &ipcp_wantoptions[0];
520 if (wo->ouraddr != 0)
521 printer(arg,
"%I", wo->ouraddr);
523 if (wo->hisaddr != 0)
524 printer(arg,
"%I", wo->hisaddr);
543 n = parse_dotted_ip(p, &mask);
547 if (n == 0 || p[n] != 0 || (netmask & ~mask) != 0) {
548 option_error(
"invalid netmask value '%s'", *argv);
553 slprintf(netmask_str,
sizeof(netmask_str),
"%I", mask);
559 parse_dotted_ip(p, vp)
569 b = strtoul(p, &endp, 0);
595 static void ipcp_init(ppp_pcb *pcb) {
596 fsm *f = &pcb->ipcp_fsm;
598 ipcp_options *wo = &pcb->ipcp_wantoptions;
599 ipcp_options *ao = &pcb->ipcp_allowoptions;
602 f->protocol = PPP_IPCP;
603 f->callbacks = &ipcp_callbacks;
612 f->maxnakloops = 100;
615 memset(wo, 0,
sizeof(*wo));
616 memset(ao, 0,
sizeof(*ao));
619 wo->neg_addr = wo->old_addrs = 1;
622 wo->vj_protocol = IPCP_VJ_COMP;
623 wo->maxslotindex = MAX_STATES - 1;
629 wo->default_route = 1;
632 ao->neg_addr = ao->old_addrs = 1;
639 ao->maxslotindex = MAX_STATES - 1;
649 ao->default_route = 1;
657 static void ipcp_open(ppp_pcb *pcb) {
658 fsm *f = &pcb->ipcp_fsm;
660 pcb->ipcp_is_open = 1;
667 static void ipcp_close(ppp_pcb *pcb,
const char *reason) {
668 fsm *f = &pcb->ipcp_fsm;
669 fsm_close(f, reason);
676 static void ipcp_lowerup(ppp_pcb *pcb) {
677 fsm *f = &pcb->ipcp_fsm;
685 static void ipcp_lowerdown(ppp_pcb *pcb) {
686 fsm *f = &pcb->ipcp_fsm;
694 static void ipcp_input(ppp_pcb *pcb, u_char *p,
int len) {
695 fsm *f = &pcb->ipcp_fsm;
696 fsm_input(f, p, len);
705 static void ipcp_protrej(ppp_pcb *pcb) {
706 fsm *f = &pcb->ipcp_fsm;
715 static void ipcp_resetci(fsm *f) {
716 ppp_pcb *pcb = f->pcb;
717 ipcp_options *wo = &pcb->ipcp_wantoptions;
718 ipcp_options *go = &pcb->ipcp_gotoptions;
719 ipcp_options *ao = &pcb->ipcp_allowoptions;
721 wo->req_addr = (wo->neg_addr || wo->old_addrs) &&
722 (ao->neg_addr || ao->old_addrs);
723 if (wo->ouraddr == 0)
724 wo->accept_local = 1;
725 if (wo->hisaddr == 0)
726 wo->accept_remote = 1;
728 wo->req_dns1 = wo->req_dns2 = pcb->settings.usepeerdns;
739 if (ip_choose_hook) {
740 ip_choose_hook(&wo->hisaddr);
742 wo->accept_remote = 0;
746 BZERO(&pcb->ipcp_hisoptions,
sizeof(ipcp_options));
754 static int ipcp_cilen(fsm *f) {
755 ppp_pcb *pcb = f->pcb;
756 ipcp_options *go = &pcb->ipcp_gotoptions;
758 ipcp_options *wo = &pcb->ipcp_wantoptions;
760 ipcp_options *ho = &pcb->ipcp_hisoptions;
762 #define LENCIADDRS(neg) (neg ? CILEN_ADDRS : 0) 764 #define LENCIVJ(neg, old) (neg ? (old? CILEN_COMPRESS : CILEN_VJ) : 0) 766 #define LENCIADDR(neg) (neg ? CILEN_ADDR : 0) 768 #define LENCIDNS(neg) LENCIADDR(neg) 771 #define LENCIWINS(neg) LENCIADDR(neg) 778 if (go->neg_addr && go->old_addrs && !ho->neg_addr && ho->old_addrs)
782 if (wo->neg_vj && !go->neg_vj && !go->old_vj) {
785 if (ho->neg_vj && ho->old_vj) {
788 go->vj_protocol = ho->vj_protocol;
793 return (LENCIADDRS(!go->neg_addr && go->old_addrs) +
795 LENCIVJ(go->neg_vj, go->old_vj) +
797 LENCIADDR(go->neg_addr) +
799 LENCIDNS(go->req_dns1) +
800 LENCIDNS(go->req_dns2) +
803 LENCIWINS(go->winsaddr[0]) +
804 LENCIWINS(go->winsaddr[1]) +
814 static void ipcp_addci(fsm *f, u_char *ucp,
int *lenp) {
815 ppp_pcb *pcb = f->pcb;
816 ipcp_options *go = &pcb->ipcp_gotoptions;
819 #define ADDCIADDRS(opt, neg, val1, val2) \ 821 if (len >= CILEN_ADDRS) { \ 824 PUTCHAR(CILEN_ADDRS, ucp); \ 829 len -= CILEN_ADDRS; \ 835 #define ADDCIVJ(opt, neg, val, old, maxslotindex, cflag) \ 837 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \ 838 if (len >= vjlen) { \ 840 PUTCHAR(vjlen, ucp); \ 841 PUTSHORT(val, ucp); \ 843 PUTCHAR(maxslotindex, ucp); \ 844 PUTCHAR(cflag, ucp); \ 852 #define ADDCIADDR(opt, neg, val) \ 854 if (len >= CILEN_ADDR) { \ 857 PUTCHAR(CILEN_ADDR, ucp); \ 866 #define ADDCIDNS(opt, neg, addr) \ 868 if (len >= CILEN_ADDR) { \ 871 PUTCHAR(CILEN_ADDR, ucp); \ 881 #define ADDCIWINS(opt, addr) \ 883 if (len >= CILEN_ADDR) { \ 886 PUTCHAR(CILEN_ADDR, ucp); \ 895 ADDCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs, go->ouraddr,
899 ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
900 go->maxslotindex, go->cflag);
903 ADDCIADDR(CI_ADDR, go->neg_addr, go->ouraddr);
906 ADDCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
908 ADDCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
912 ADDCIWINS(CI_MS_WINS1, go->winsaddr[0]);
914 ADDCIWINS(CI_MS_WINS2, go->winsaddr[1]);
929 static int ipcp_ackci(fsm *f, u_char *p,
int len) {
930 ppp_pcb *pcb = f->pcb;
931 ipcp_options *go = &pcb->ipcp_gotoptions;
932 u_short cilen, citype;
936 u_char cimaxslotindex, cicflag;
945 #define ACKCIADDRS(opt, neg, val1, val2) \ 948 if ((len -= CILEN_ADDRS) < 0) \ 950 GETCHAR(citype, p); \ 952 if (cilen != CILEN_ADDRS || \ 957 if (val1 != cilong) \ 961 if (val2 != cilong) \ 966 #define ACKCIVJ(opt, neg, val, old, maxslotindex, cflag) \ 968 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \ 969 if ((len -= vjlen) < 0) \ 971 GETCHAR(citype, p); \ 973 if (cilen != vjlen || \ 976 GETSHORT(cishort, p); \ 977 if (cishort != val) \ 980 GETCHAR(cimaxslotindex, p); \ 981 if (cimaxslotindex != maxslotindex) \ 983 GETCHAR(cicflag, p); \ 984 if (cicflag != cflag) \ 990 #define ACKCIADDR(opt, neg, val) \ 993 if ((len -= CILEN_ADDR) < 0) \ 995 GETCHAR(citype, p); \ 997 if (cilen != CILEN_ADDR || \ 1001 cilong = htonl(l); \ 1002 if (val != cilong) \ 1007 #define ACKCIDNS(opt, neg, addr) \ 1010 if ((len -= CILEN_ADDR) < 0) \ 1012 GETCHAR(citype, p); \ 1013 GETCHAR(cilen, p); \ 1014 if (cilen != CILEN_ADDR || citype != opt) \ 1017 cilong = htonl(l); \ 1018 if (addr != cilong) \ 1024 #define ACKCIWINS(opt, addr) \ 1027 if ((len -= CILEN_ADDR) < 0) \ 1029 GETCHAR(citype, p); \ 1030 GETCHAR(cilen, p); \ 1031 if (cilen != CILEN_ADDR || citype != opt) \ 1034 cilong = htonl(l); \ 1035 if (addr != cilong) \ 1040 ACKCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs, go->ouraddr,
1044 ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
1045 go->maxslotindex, go->cflag);
1048 ACKCIADDR(CI_ADDR, go->neg_addr, go->ouraddr);
1051 ACKCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
1053 ACKCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
1057 ACKCIWINS(CI_MS_WINS1, go->winsaddr[0]);
1059 ACKCIWINS(CI_MS_WINS2, go->winsaddr[1]);
1070 IPCPDEBUG((
"ipcp_ackci: received bad Ack!"));
1084 static int ipcp_nakci(fsm *f, u_char *p,
int len,
int treat_as_reject) {
1085 ppp_pcb *pcb = f->pcb;
1086 ipcp_options *go = &pcb->ipcp_gotoptions;
1087 u_char citype, cilen, *next;
1089 u_char cimaxslotindex, cicflag;
1092 u32_t ciaddr1, ciaddr2, l;
1099 BZERO(&no,
sizeof(no));
1107 #define NAKCIADDRS(opt, neg, code) \ 1109 (cilen = p[1]) == CILEN_ADDRS && \ 1115 ciaddr1 = htonl(l); \ 1117 ciaddr2 = htonl(l); \ 1123 #define NAKCIVJ(opt, neg, code) \ 1125 ((cilen = p[1]) == CILEN_COMPRESS || cilen == CILEN_VJ) && \ 1130 GETSHORT(cishort, p); \ 1136 #define NAKCIADDR(opt, neg, code) \ 1138 (cilen = p[1]) == CILEN_ADDR && \ 1144 ciaddr1 = htonl(l); \ 1150 #define NAKCIDNS(opt, neg, code) \ 1152 ((cilen = p[1]) == CILEN_ADDR) && \ 1158 cidnsaddr = htonl(l); \ 1168 NAKCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs,
1169 if (treat_as_reject) {
1172 if (go->accept_local && ciaddr1) {
1174 try_.ouraddr = ciaddr1;
1176 if (go->accept_remote && ciaddr2) {
1178 try_.hisaddr = ciaddr2;
1190 NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
1191 if (treat_as_reject) {
1193 }
else if (cilen == CILEN_VJ) {
1194 GETCHAR(cimaxslotindex, p);
1195 GETCHAR(cicflag, p);
1196 if (cishort == IPCP_VJ_COMP) {
1198 if (cimaxslotindex < go->maxslotindex)
1199 try_.maxslotindex = cimaxslotindex;
1206 if (cishort == IPCP_VJ_COMP || cishort == IPCP_VJ_COMP_OLD) {
1208 try_.vj_protocol = cishort;
1216 NAKCIADDR(CI_ADDR, neg_addr,
1217 if (treat_as_reject) {
1220 }
else if (go->accept_local && ciaddr1) {
1222 try_.ouraddr = ciaddr1;
1227 NAKCIDNS(CI_MS_DNS1, req_dns1,
1228 if (treat_as_reject) {
1231 try_.dnsaddr[0] = cidnsaddr;
1235 NAKCIDNS(CI_MS_DNS2, req_dns2,
1236 if (treat_as_reject) {
1239 try_.dnsaddr[1] = cidnsaddr;
1252 while (len >= CILEN_VOID) {
1255 if ( cilen < CILEN_VOID || (len -= cilen) < 0 )
1257 next = p + cilen - 2;
1261 case CI_COMPRESSTYPE:
1262 if (go->neg_vj || no.neg_vj ||
1263 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS))
1269 if ((!go->neg_addr && go->old_addrs) || no.old_addrs
1270 || cilen != CILEN_ADDRS)
1275 if (ciaddr1 && go->accept_local)
1276 try_.ouraddr = ciaddr1;
1279 if (ciaddr2 && go->accept_remote)
1280 try_.hisaddr = ciaddr2;
1284 if (go->neg_addr || no.neg_addr || cilen != CILEN_ADDR)
1289 if (ciaddr1 && go->accept_local)
1290 try_.ouraddr = ciaddr1;
1291 if (try_.ouraddr != 0)
1297 if (go->req_dns1 || no.req_dns1 || cilen != CILEN_ADDR)
1300 try_.dnsaddr[0] =
htonl(l);
1305 if (go->req_dns2 || no.req_dns2 || cilen != CILEN_ADDR)
1308 try_.dnsaddr[1] =
htonl(l);
1316 if (cilen != CILEN_ADDR)
1321 try_.winsaddr[citype == CI_MS_WINS2] = ciaddr1;
1334 if (f->state != PPP_FSM_OPENED)
1340 IPCPDEBUG((
"ipcp_nakci: received bad Nak!"));
1349 static int ipcp_rejci(fsm *f, u_char *p,
int len) {
1350 ppp_pcb *pcb = f->pcb;
1351 ipcp_options *go = &pcb->ipcp_gotoptions;
1354 u_char cimaxslotindex, ciflag;
1366 #define REJCIADDRS(opt, neg, val1, val2) \ 1368 (cilen = p[1]) == CILEN_ADDRS && \ 1375 cilong = htonl(l); \ 1377 if (cilong != val1) \ 1380 cilong = htonl(l); \ 1382 if (cilong != val2) \ 1384 try_.old_addrs = 0; \ 1388 #define REJCIVJ(opt, neg, val, old, maxslot, cflag) \ 1390 p[1] == (old? CILEN_COMPRESS : CILEN_VJ) && \ 1395 GETSHORT(cishort, p); \ 1397 if (cishort != val) \ 1400 GETCHAR(cimaxslotindex, p); \ 1401 if (cimaxslotindex != maxslot) \ 1403 GETCHAR(ciflag, p); \ 1404 if (ciflag != cflag) \ 1411 #define REJCIADDR(opt, neg, val) \ 1413 (cilen = p[1]) == CILEN_ADDR && \ 1420 cilong = htonl(l); \ 1422 if (cilong != val) \ 1428 #define REJCIDNS(opt, neg, dnsaddr) \ 1430 ((cilen = p[1]) == CILEN_ADDR) && \ 1437 cilong = htonl(l); \ 1439 if (cilong != dnsaddr) \ 1446 #define REJCIWINS(opt, addr) \ 1448 ((cilen = p[1]) == CILEN_ADDR) && \ 1455 cilong = htonl(l); \ 1457 if (cilong != addr) \ 1459 try_.winsaddr[opt == CI_MS_WINS2] = 0; \ 1463 REJCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs,
1464 go->ouraddr, go->hisaddr);
1467 REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol, go->old_vj,
1468 go->maxslotindex, go->cflag);
1471 REJCIADDR(CI_ADDR, neg_addr, go->ouraddr);
1474 REJCIDNS(CI_MS_DNS1, req_dns1, go->dnsaddr[0]);
1476 REJCIDNS(CI_MS_DNS2, req_dns2, go->dnsaddr[1]);
1480 REJCIWINS(CI_MS_WINS1, go->winsaddr[0]);
1482 REJCIWINS(CI_MS_WINS2, go->winsaddr[1]);
1493 if (f->state != PPP_FSM_OPENED)
1498 IPCPDEBUG((
"ipcp_rejci: received bad Reject!"));
1514 static int ipcp_reqci(fsm *f, u_char *inp,
int *len,
int reject_if_disagree) {
1515 ppp_pcb *pcb = f->pcb;
1516 ipcp_options *wo = &pcb->ipcp_wantoptions;
1517 ipcp_options *ho = &pcb->ipcp_hisoptions;
1518 ipcp_options *ao = &pcb->ipcp_allowoptions;
1520 u_short cilen, citype;
1524 u32_t tl, ciaddr1, ciaddr2;
1531 u_char maxslotindex, cflag;
1540 BZERO(ho,
sizeof(*ho));
1552 IPCPDEBUG((
"ipcp_reqci: bad CI length!"));
1565 if (!ao->old_addrs || ho->neg_addr ||
1566 cilen != CILEN_ADDRS) {
1578 ciaddr1 =
htonl(tl);
1579 if (ciaddr1 != wo->hisaddr
1580 && (ciaddr1 == 0 || !wo->accept_remote)) {
1582 if (!reject_if_disagree) {
1583 DECPTR(
sizeof(
u32_t), p);
1584 tl =
ntohl(wo->hisaddr);
1587 }
else if (ciaddr1 == 0 && wo->hisaddr == 0) {
1601 ciaddr2 =
htonl(tl);
1602 if (ciaddr2 != wo->ouraddr) {
1603 if (ciaddr2 == 0 || !wo->accept_local) {
1605 if (!reject_if_disagree) {
1606 DECPTR(
sizeof(
u32_t), p);
1607 tl =
ntohl(wo->ouraddr);
1611 wo->ouraddr = ciaddr2;
1616 ho->hisaddr = ciaddr1;
1617 ho->ouraddr = ciaddr2;
1621 if (!ao->neg_addr || ho->old_addrs ||
1622 cilen != CILEN_ADDR) {
1634 ciaddr1 =
htonl(tl);
1635 if (ciaddr1 != wo->hisaddr
1636 && (ciaddr1 == 0 || !wo->accept_remote)) {
1638 if (!reject_if_disagree) {
1639 DECPTR(
sizeof(
u32_t), p);
1640 tl =
ntohl(wo->hisaddr);
1643 }
else if (ciaddr1 == 0 && wo->hisaddr == 0) {
1653 ho->hisaddr = ciaddr1;
1660 d = citype == CI_MS_DNS2;
1663 if (ao->dnsaddr[d] == 0 ||
1664 cilen != CILEN_ADDR) {
1669 if (
htonl(tl) != ao->dnsaddr[d]) {
1670 DECPTR(
sizeof(
u32_t), p);
1671 tl =
ntohl(ao->dnsaddr[d]);
1682 d = citype == CI_MS_WINS2;
1685 if (ao->winsaddr[d] == 0 ||
1686 cilen != CILEN_ADDR) {
1691 if (
htonl(tl) != ao->winsaddr[d]) {
1692 DECPTR(
sizeof(
u32_t), p);
1693 tl =
ntohl(ao->winsaddr[d]);
1701 case CI_COMPRESSTYPE:
1703 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS)) {
1707 GETSHORT(cishort, p);
1709 if (!(cishort == IPCP_VJ_COMP ||
1710 (cishort == IPCP_VJ_COMP_OLD && cilen == CILEN_COMPRESS))) {
1716 ho->vj_protocol = cishort;
1717 if (cilen == CILEN_VJ) {
1718 GETCHAR(maxslotindex, p);
1719 if (maxslotindex > ao->maxslotindex) {
1721 if (!reject_if_disagree){
1723 PUTCHAR(ao->maxslotindex, p);
1727 if (cflag && !ao->cflag) {
1729 if (!reject_if_disagree){
1731 PUTCHAR(wo->cflag, p);
1734 ho->maxslotindex = maxslotindex;
1738 ho->maxslotindex = MAX_STATES - 1;
1749 if (orc == CONFACK &&
1753 if (orc == CONFNAK) {
1754 if (reject_if_disagree)
1759 if (rc == CONFACK) {
1766 if (orc == CONFREJ &&
1787 if (rc != CONFREJ && !ho->neg_addr && !ho->old_addrs &&
1788 wo->req_addr && !reject_if_disagree && !pcb->settings.noremoteip) {
1789 if (rc == CONFACK) {
1794 PUTCHAR(CI_ADDR, ucp);
1795 PUTCHAR(CILEN_ADDR, ucp);
1796 tl =
ntohl(wo->hisaddr);
1801 IPCPDEBUG((
"ipcp: returning Configure-%s", CODENAME(rc)));
1816 ipcp_options *wo = &ipcp_wantoptions[0];
1822 if (wo->ouraddr == 0 && !disable_defaultip) {
1828 wo->accept_local = 1;
1829 if ((hp = gethostbyname(hostname)) !=
NULL) {
1830 local = *(
u32_t *)hp->h_addr;
1831 if (local != 0 && !bad_ip_adrs(local))
1832 wo->ouraddr = local;
1835 ask_for_local = wo->ouraddr != 0 || !disable_defaultip;
1848 ppp_pcb *pcb = &ppp_pcb_list[u];
1849 ipcp_options *wo = &ipcp_wantoptions[u];
1851 if (wo->hisaddr == 0 && !pcb->settings.noremoteip) {
1853 wo->hisaddr =
htonl(0x0a707070 + ifunit);
1854 wo->accept_remote = 1;
1856 if (wo->ouraddr == 0) {
1858 wo->ouraddr =
htonl(0x0a404040 + ifunit);
1859 wo->accept_local = 1;
1862 if (!sifaddr(pcb, wo->ouraddr, wo->hisaddr, get_mask(wo->ouraddr)))
1866 if (!sifnpmode(pcb, PPP_IP, NPMODE_QUEUE))
1869 if (wo->default_route)
1870 if (sifdefaultroute(pcb, wo->ouraddr, wo->hisaddr,
1871 wo->replace_default_route))
1872 default_route_set[u] = 1;
1876 if (sifproxyarp(pcb, wo->hisaddr))
1877 proxy_arp_set[u] = 1;
1880 ppp_notice(
"local IP address %I", wo->ouraddr);
1882 ppp_notice(
"remote IP address %I", wo->hisaddr);
1893 static void ipcp_up(fsm *f) {
1894 ppp_pcb *pcb = f->pcb;
1896 ipcp_options *ho = &pcb->ipcp_hisoptions;
1897 ipcp_options *go = &pcb->ipcp_gotoptions;
1898 ipcp_options *wo = &pcb->ipcp_wantoptions;
1900 IPCPDEBUG((
"ipcp: up"));
1905 if (!ho->neg_addr && !ho->old_addrs)
1906 ho->hisaddr = wo->hisaddr;
1908 if (!(go->neg_addr || go->old_addrs) && (wo->neg_addr || wo->old_addrs)
1909 && wo->ouraddr != 0) {
1910 ppp_error(
"Peer refused to agree to our IP address");
1911 ipcp_close(f->pcb,
"Refused our IP address");
1914 if (go->ouraddr == 0) {
1915 ppp_error(
"Could not determine local IP address");
1916 ipcp_close(f->pcb,
"Could not determine local IP address");
1919 if (ho->hisaddr == 0 && !pcb->settings.noremoteip) {
1920 ho->hisaddr =
htonl(0x0a404040);
1921 ppp_warn(
"Could not determine remote IP address: defaulting to %I",
1925 script_setenv(
"IPLOCAL", ip_ntoa(go->ouraddr), 0);
1926 if (ho->hisaddr != 0)
1927 script_setenv(
"IPREMOTE", ip_ntoa(ho->hisaddr), 1);
1937 script_setenv(
"DNS1", ip_ntoa(go->dnsaddr[0]), 0);
1939 script_setenv(
"DNS2", ip_ntoa(go->dnsaddr[1]), 0);
1941 if (pcb->settings.usepeerdns && (go->dnsaddr[0] || go->dnsaddr[1])) {
1942 sdns(pcb, go->dnsaddr[0], go->dnsaddr[1]);
1944 script_setenv(
"USEPEERDNS",
"1", 0);
1945 create_resolv(go->dnsaddr[0], go->dnsaddr[1]);
1955 if (ho->hisaddr != 0 && !auth_ip_addr(f->unit, ho->hisaddr)) {
1956 ppp_error(
"Peer is not authorized to use remote address %I", ho->hisaddr);
1957 ipcp_close(f->unit,
"Unauthorized remote IP address");
1964 sifvjcomp(pcb, ho->neg_vj, ho->cflag, ho->maxslotindex);
1974 if (go->ouraddr != wo->ouraddr || ho->hisaddr != wo->hisaddr) {
1975 ipcp_clear_addrs(f->unit, wo->ouraddr, wo->hisaddr,
1976 wo->replace_default_route);
1977 if (go->ouraddr != wo->ouraddr) {
1978 ppp_warn(
"Local IP address changed to %I", go->ouraddr);
1979 script_setenv(
"OLDIPLOCAL", ip_ntoa(wo->ouraddr), 0);
1980 wo->ouraddr = go->ouraddr;
1982 script_unsetenv(
"OLDIPLOCAL");
1983 if (ho->hisaddr != wo->hisaddr && wo->hisaddr != 0) {
1984 ppp_warn(
"Remote IP address changed to %I", ho->hisaddr);
1985 script_setenv(
"OLDIPREMOTE", ip_ntoa(wo->hisaddr), 0);
1986 wo->hisaddr = ho->hisaddr;
1988 script_unsetenv(
"OLDIPREMOTE");
1991 mask = get_mask(go->ouraddr);
1992 if (!sifaddr(pcb, go->ouraddr, ho->hisaddr, mask)) {
1994 ppp_warn(
"Interface configuration failed");
1996 ipcp_close(f->unit,
"Interface configuration failed");
2001 if (ipcp_wantoptions[f->unit].default_route)
2002 if (sifdefaultroute(pcb, go->ouraddr, ho->hisaddr,
2003 wo->replace_default_route))
2004 default_route_set[f->unit] = 1;
2008 if (ho->hisaddr != 0 && ipcp_wantoptions[f->unit].proxy_arp)
2009 if (sifproxyarp(pcb, ho->hisaddr))
2010 proxy_arp_set[f->unit] = 1;
2014 demand_rexmit(PPP_IP,go->ouraddr);
2015 sifnpmode(pcb, PPP_IP, NPMODE_PASS);
2023 mask = get_mask(go->ouraddr);
2025 #if !(defined(SVR4) && (defined(SNI) || defined(__USLC__))) 2026 if (!sifaddr(pcb, go->ouraddr, ho->hisaddr, mask)) {
2028 ppp_warn(
"Interface configuration failed");
2030 ipcp_close(f->pcb,
"Interface configuration failed");
2038 ppp_warn(
"Interface failed to come up");
2040 ipcp_close(f->pcb,
"Interface configuration failed");
2044 #if (defined(SVR4) && (defined(SNI) || defined(__USLC__))) 2045 if (!sifaddr(pcb, go->ouraddr, ho->hisaddr, mask)) {
2047 ppp_warn(
"Interface configuration failed");
2049 ipcp_close(f->unit,
"Interface configuration failed");
2054 sifnpmode(pcb, PPP_IP, NPMODE_PASS);
2059 if (wo->default_route)
2060 if (sifdefaultroute(pcb, go->ouraddr, ho->hisaddr,
2061 wo->replace_default_route))
2062 pcb->default_route_set = 1;
2067 if (ho->hisaddr != 0 && wo->proxy_arp)
2068 if (sifproxyarp(pcb, ho->hisaddr))
2069 pcb->proxy_arp_set = 1;
2072 wo->ouraddr = go->ouraddr;
2074 ppp_notice(
"local IP address %I", go->ouraddr);
2075 if (ho->hisaddr != 0)
2076 ppp_notice(
"remote IP address %I", ho->hisaddr);
2079 ppp_notice(
"primary DNS address %I", go->dnsaddr[0]);
2081 ppp_notice(
"secondary DNS address %I", go->dnsaddr[1]);
2085 #if PPP_STATS_SUPPORT 2086 reset_link_stats(f->unit);
2090 pcb->ipcp_is_up = 1;
2093 notify(ip_up_notifier, 0);
2108 static void ipcp_down(fsm *f) {
2109 ppp_pcb *pcb = f->pcb;
2110 ipcp_options *ho = &pcb->ipcp_hisoptions;
2111 ipcp_options *go = &pcb->ipcp_gotoptions;
2113 IPCPDEBUG((
"ipcp: down"));
2114 #if PPP_STATS_SUPPORT 2119 update_link_stats(f->unit);
2122 notify(ip_down_notifier, 0);
2128 if (pcb->ipcp_is_up) {
2129 pcb->ipcp_is_up = 0;
2130 np_down(pcb, PPP_IP);
2133 sifvjcomp(pcb, 0, 0, 0);
2136 #if PPP_STATS_SUPPORT 2148 sifnpmode(pcb, PPP_IP, NPMODE_QUEUE);
2153 sifnpmode(pcb, PPP_IP, NPMODE_DROP);
2156 ipcp_clear_addrs(pcb, go->ouraddr,
2159 cdns(pcb, go->dnsaddr[0], go->dnsaddr[1]);
2169 static void ipcp_clear_addrs(ppp_pcb *pcb,
u32_t ouraddr,
u32_t hisaddr,
u8_t replacedefaultroute) {
2173 if (pcb->proxy_arp_set) {
2174 cifproxyarp(pcb, hisaddr);
2175 pcb->proxy_arp_set = 0;
2187 if (!replacedefaultroute && pcb->default_route_set) {
2188 cifdefaultroute(pcb, ouraddr, hisaddr);
2189 pcb->default_route_set = 0;
2192 cifaddr(pcb, ouraddr, hisaddr);
2199 static void ipcp_finished(fsm *f) {
2200 ppp_pcb *pcb = f->pcb;
2201 if (pcb->ipcp_is_open) {
2202 pcb->ipcp_is_open = 0;
2203 np_finished(pcb, PPP_IP);
2213 create_resolv(peerdns1, peerdns2)
2214 u32_t peerdns1, peerdns2;
2220 #if PRINTPKT_SUPPORT 2224 static const char*
const ipcp_codenames[] = {
2225 "ConfReq",
"ConfAck",
"ConfNak",
"ConfRej",
2226 "TermReq",
"TermAck",
"CodeRej" 2229 static int ipcp_printpkt(
const u_char *p,
int plen,
2230 void (*printer) (
void *,
const char *, ...),
void *arg) {
2231 int code, id, len, olen;
2232 const u_char *pstart, *optend;
2238 if (plen < HEADERLEN)
2244 if (len < HEADERLEN || len > plen)
2247 if (code >= 1 && code <= (
int)
sizeof(ipcp_codenames) / (
int)
sizeof(
char *))
2248 printer(arg,
" %s", ipcp_codenames[code-1]);
2250 printer(arg,
" code=0x%x", code);
2251 printer(arg,
" id=0x%x",
id);
2263 if (olen < 2 || olen > len) {
2271 if (olen == CILEN_ADDRS) {
2274 printer(arg,
"addrs %I",
htonl(cilong));
2276 printer(arg,
" %I",
htonl(cilong));
2280 case CI_COMPRESSTYPE:
2281 if (olen >= CILEN_COMPRESS) {
2283 GETSHORT(cishort, p);
2284 printer(arg,
"compress ");
2289 case IPCP_VJ_COMP_OLD:
2290 printer(arg,
"old-VJ");
2293 printer(arg,
"0x%x", cishort);
2299 if (olen == CILEN_ADDR) {
2302 printer(arg,
"addr %I",
htonl(cilong));
2310 printer(arg,
"ms-dns%d %I", (code == CI_MS_DNS1? 1: 2),
2319 printer(arg,
"ms-wins %I",
htonl(cilong));
2325 while (p < optend) {
2327 printer(arg,
" %.2x", code);
2335 if (len > 0 && *p >=
' ' && *p < 0x7f) {
2337 ppp_print_string(p, len, printer, arg);
2347 for (; len > 0; --len) {
2349 printer(arg,
" %.2x", code);
2362 #define IP_HDRLEN 20 2363 #define IP_OFFMASK 0x1fff 2365 #define IPPROTO_TCP 6 2367 #define TCP_HDRLEN 20 2375 #define net_short(x) (((x)[0] << 8) + (x)[1]) 2376 #define get_iphl(x) (((unsigned char *)(x))[0] & 0xF) 2377 #define get_ipoff(x) net_short((unsigned char *)(x) + 6) 2378 #define get_ipproto(x) (((unsigned char *)(x))[9]) 2379 #define get_tcpoff(x) (((unsigned char *)(x))[12] >> 4) 2380 #define get_tcpflags(x) (((unsigned char *)(x))[13]) 2383 ip_active_pkt(pkt, len)
2392 if (len < IP_HDRLEN)
2394 if ((get_ipoff(pkt) & IP_OFFMASK) != 0)
2396 if (get_ipproto(pkt) != IPPROTO_TCP)
2398 hlen = get_iphl(pkt) * 4;
2399 if (len < hlen + TCP_HDRLEN)
2402 if ((get_tcpflags(tcp) & TH_FIN) != 0 && len == hlen + get_tcpoff(tcp) * 4)
#define MEMCPY(dst, src, len)
#define LWIP_UNUSED_ARG(x)