2 * ipcp.c - PPP IP Control Protocol.
4 * Copyright (c) 1989 Carnegie Mellon University.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by Carnegie Mellon University. The name of the
13 * University may not be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 #define RCSID "$Id: ipcp.c,v 1.56 2001/02/22 03:15:16 paulus Exp $"
30 #include <sys/param.h>
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
39 #include "pathnames.h"
41 static const char rcsid[] = RCSID;
44 ipcp_options ipcp_wantoptions[NUM_PPP]; /* Options that we want to request */
45 ipcp_options ipcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
46 ipcp_options ipcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
47 ipcp_options ipcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
49 u_int32_t netmask = 0; /* IP netmask to set on interface */
51 bool disable_defaultip = 0; /* Don't use hostname for default IP adrs */
53 /* Hook for a plugin to know when IP protocol has come up */
54 void (*ip_up_hook) __P((void)) = NULL;
56 /* Hook for a plugin to know when IP protocol has come down */
57 void (*ip_down_hook) __P((void)) = NULL;
59 /* Hook for a plugin to choose the remote IP address */
60 void (*ip_choose_hook) __P((u_int32_t *)) = NULL;
63 static int default_route_set[NUM_PPP]; /* Have set up a default route */
64 static int proxy_arp_set[NUM_PPP]; /* Have created proxy arp entry */
65 static bool usepeerdns; /* Ask peer for DNS addrs */
66 static int ipcp_is_up; /* have called np_up() */
67 static bool ask_for_local; /* request our address from peer */
70 * Callbacks for fsm code. (CI = Configuration Information)
72 static void ipcp_resetci __P((fsm *)); /* Reset our CI */
73 static int ipcp_cilen __P((fsm *)); /* Return length of our CI */
74 static void ipcp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
75 static int ipcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
76 static int ipcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
77 static int ipcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
78 static int ipcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
79 static void ipcp_up __P((fsm *)); /* We're UP */
80 static void ipcp_down __P((fsm *)); /* We're DOWN */
81 static void ipcp_finished __P((fsm *)); /* Don't need lower layer */
83 fsm ipcp_fsm[NUM_PPP]; /* IPCP fsm structure */
85 static fsm_callbacks ipcp_callbacks = { /* IPCP callback routines */
86 ipcp_resetci, /* Reset our Configuration Information */
87 ipcp_cilen, /* Length of our Configuration Information */
88 ipcp_addci, /* Add our Configuration Information */
89 ipcp_ackci, /* ACK our Configuration Information */
90 ipcp_nakci, /* NAK our Configuration Information */
91 ipcp_rejci, /* Reject our Configuration Information */
92 ipcp_reqci, /* Request peer's Configuration Information */
93 ipcp_up, /* Called when fsm reaches OPENED state */
94 ipcp_down, /* Called when fsm leaves OPENED state */
95 NULL, /* Called when we want the lower layer up */
96 ipcp_finished, /* Called when we want the lower layer down */
97 NULL, /* Called when Protocol-Reject received */
98 NULL, /* Retransmission is necessary */
99 NULL, /* Called to handle protocol-specific codes */
100 "IPCP" /* String name of protocol */
104 * Command-line options.
106 static int setvjslots __P((char **));
107 static int setdnsaddr __P((char **));
108 static int setwinsaddr __P((char **));
109 static int setnetmask __P((char **));
110 static int setipaddr __P((char *, char **, int));
112 static option_t ipcp_option_list[] = {
113 { "noip", o_bool, &ipcp_protent.enabled_flag,
114 "Disable IP and IPCP" },
115 { "-ip", o_bool, &ipcp_protent.enabled_flag,
116 "Disable IP and IPCP" },
117 { "novj", o_bool, &ipcp_wantoptions[0].neg_vj,
118 "Disable VJ compression", OPT_A2COPY, &ipcp_allowoptions[0].neg_vj },
119 { "-vj", o_bool, &ipcp_wantoptions[0].neg_vj,
120 "Disable VJ compression", OPT_A2COPY, &ipcp_allowoptions[0].neg_vj },
121 { "novjccomp", o_bool, &ipcp_wantoptions[0].cflag,
122 "Disable VJ connection-ID compression", OPT_A2COPY,
123 &ipcp_allowoptions[0].cflag },
124 { "-vjccomp", o_bool, &ipcp_wantoptions[0].cflag,
125 "Disable VJ connection-ID compression", OPT_A2COPY,
126 &ipcp_allowoptions[0].cflag },
127 { "vj-max-slots", o_special, (void *)setvjslots,
128 "Set maximum VJ header slots" },
129 { "ipcp-accept-local", o_bool, &ipcp_wantoptions[0].accept_local,
130 "Accept peer's address for us", 1 },
131 { "ipcp-accept-remote", o_bool, &ipcp_wantoptions[0].accept_remote,
132 "Accept peer's address for it", 1 },
133 { "ipparam", o_string, &ipparam,
134 "Set ip script parameter" },
135 { "noipdefault", o_bool, &disable_defaultip,
136 "Don't use name for default IP adrs", 1 },
137 { "ms-dns", 1, (void *)setdnsaddr,
138 "DNS address for the peer's use" },
139 { "ms-wins", 1, (void *)setwinsaddr,
140 "Nameserver for SMB over TCP/IP for peer" },
141 { "ipcp-restart", o_int, &ipcp_fsm[0].timeouttime,
142 "Set timeout for IPCP" },
143 { "ipcp-max-terminate", o_int, &ipcp_fsm[0].maxtermtransmits,
144 "Set max #xmits for term-reqs" },
145 { "ipcp-max-configure", o_int, &ipcp_fsm[0].maxconfreqtransmits,
146 "Set max #xmits for conf-reqs" },
147 { "ipcp-max-failure", o_int, &ipcp_fsm[0].maxnakloops,
148 "Set max #conf-naks for IPCP" },
149 { "defaultroute", o_bool, &ipcp_wantoptions[0].default_route,
150 "Add default route", OPT_ENABLE|1, &ipcp_allowoptions[0].default_route },
151 { "nodefaultroute", o_bool, &ipcp_allowoptions[0].default_route,
152 "disable defaultroute option", OPT_A2COPY,
153 &ipcp_wantoptions[0].default_route },
154 { "-defaultroute", o_bool, &ipcp_allowoptions[0].default_route,
155 "disable defaultroute option", OPT_A2COPY,
156 &ipcp_wantoptions[0].default_route },
157 { "proxyarp", o_bool, &ipcp_wantoptions[0].proxy_arp,
158 "Add proxy ARP entry", OPT_ENABLE|1, &ipcp_allowoptions[0].proxy_arp },
159 { "noproxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
160 "disable proxyarp option", OPT_A2COPY,
161 &ipcp_wantoptions[0].proxy_arp },
162 { "-proxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
163 "disable proxyarp option", OPT_A2COPY,
164 &ipcp_wantoptions[0].proxy_arp },
165 { "usepeerdns", o_bool, &usepeerdns,
166 "Ask peer for DNS address(es)", 1 },
167 { "netmask", o_special, (void *)setnetmask,
169 { "IP addresses", o_wild, (void *) &setipaddr,
170 "set local and remote IP addresses", OPT_NOARG | OPT_MULTIPART },
175 * Protocol entry points from main code.
177 static void ipcp_init __P((int));
178 static void ipcp_open __P((int));
179 static void ipcp_close __P((int, char *));
180 static void ipcp_lowerup __P((int));
181 static void ipcp_lowerdown __P((int));
182 static void ipcp_input __P((int, u_char *, int));
183 static void ipcp_protrej __P((int));
184 static int ipcp_printpkt __P((u_char *, int,
185 void (*) __P((void *, char *, ...)), void *));
186 static void ip_check_options __P((void));
187 static int ip_demand_conf __P((int));
188 static int ip_active_pkt __P((u_char *, int));
189 static void create_resolv __P((u_int32_t, u_int32_t));
191 struct protent ipcp_protent = {
211 static void ipcp_clear_addrs __P((int, u_int32_t, u_int32_t));
212 static void ipcp_script __P((char *)); /* Run an up/down script */
213 static void ipcp_script_done __P((void *));
216 * Lengths of configuration options.
219 #define CILEN_COMPRESS 4 /* min length for compression protocol opt. */
220 #define CILEN_VJ 6 /* length for RFC1332 Van-Jacobson opt. */
221 #define CILEN_ADDR 6 /* new-style single address option */
222 #define CILEN_ADDRS 10 /* old-style dual address option */
225 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
226 (x) == CONFNAK ? "NAK" : "REJ")
229 * This state variable is used to ensure that we don't
230 * run an ipcp-up/down script while one is already running.
232 static enum script_state {
236 static pid_t ipcp_script_pid;
239 * Make a string representation of a network IP address.
247 slprintf(b, sizeof(b), "%I", ipaddr);
256 * setvjslots - set maximum number of connection slots for VJ compression
264 if (!int_option(*argv, &value))
266 if (value < 2 || value > 16) {
267 option_error("vj-max-slots value must be between 2 and 16");
270 ipcp_wantoptions [0].maxslotindex =
271 ipcp_allowoptions[0].maxslotindex = value - 1;
276 * setdnsaddr - set the dns address(es)
285 dns = inet_addr(*argv);
286 if (dns == (u_int32_t) -1) {
287 if ((hp = gethostbyname(*argv)) == NULL) {
288 option_error("invalid address parameter '%s' for ms-dns option",
292 dns = *(u_int32_t *)hp->h_addr;
295 /* if there is no primary then update it. */
296 if (ipcp_allowoptions[0].dnsaddr[0] == 0)
297 ipcp_allowoptions[0].dnsaddr[0] = dns;
299 /* always set the secondary address value to the same value. */
300 ipcp_allowoptions[0].dnsaddr[1] = dns;
306 * setwinsaddr - set the wins address(es)
307 * This is primrarly used with the Samba package under UNIX or for pointing
308 * the caller to the existing WINS server on a Windows NT platform.
317 wins = inet_addr(*argv);
318 if (wins == (u_int32_t) -1) {
319 if ((hp = gethostbyname(*argv)) == NULL) {
320 option_error("invalid address parameter '%s' for ms-wins option",
324 wins = *(u_int32_t *)hp->h_addr;
327 /* if there is no primary then update it. */
328 if (ipcp_allowoptions[0].winsaddr[0] == 0)
329 ipcp_allowoptions[0].winsaddr[0] = wins;
331 /* always set the secondary address value to the same value. */
332 ipcp_allowoptions[0].winsaddr[1] = wins;
338 * setipaddr - Set the IP address
339 * If doit is 0, the call is to check whether this option is
340 * potentially an IP address specification.
343 setipaddr(arg, argv, doit)
350 u_int32_t local, remote;
351 ipcp_options *wo = &ipcp_wantoptions[0];
352 static int prio_local = 0, prio_remote = 0;
355 * IP address pair separated by ":".
357 if ((colon = strchr(arg, ':')) == NULL)
363 * If colon first character, then no local addr.
365 if (colon != arg && option_priority >= prio_local) {
367 if ((local = inet_addr(arg)) == (u_int32_t) -1) {
368 if ((hp = gethostbyname(arg)) == NULL) {
369 option_error("unknown host: %s", arg);
372 local = *(u_int32_t *)hp->h_addr;
374 if (bad_ip_adrs(local)) {
375 option_error("bad local IP address %s", ip_ntoa(local));
381 prio_local = option_priority;
385 * If colon last character, then no remote addr.
387 if (*++colon != '\0' && option_priority >= prio_remote) {
388 if ((remote = inet_addr(colon)) == (u_int32_t) -1) {
389 if ((hp = gethostbyname(colon)) == NULL) {
390 option_error("unknown host: %s", colon);
393 remote = *(u_int32_t *)hp->h_addr;
394 if (remote_name[0] == 0)
395 strlcpy(remote_name, colon, sizeof(remote_name));
397 if (bad_ip_adrs(remote)) {
398 option_error("bad remote IP address %s", ip_ntoa(remote));
402 wo->hisaddr = remote;
403 prio_remote = option_priority;
410 * setnetmask - set the netmask to be used on the interface.
421 * Unfortunately, if we use inet_addr, we can't tell whether
422 * a result of all 1s is an error or a valid 255.255.255.255.
425 n = parse_dotted_ip(p, &mask);
429 if (n == 0 || p[n] != 0 || (netmask & ~mask) != 0) {
430 option_error("invalid netmask value '%s'", *argv);
439 parse_dotted_ip(p, vp)
449 b = strtoul(p, &endp, 0);
455 /* accept e.g. 0xffffff00 */
473 * ipcp_init - Initialize IPCP.
479 fsm *f = &ipcp_fsm[unit];
480 ipcp_options *wo = &ipcp_wantoptions[unit];
481 ipcp_options *ao = &ipcp_allowoptions[unit];
484 f->protocol = PPP_IPCP;
485 f->callbacks = &ipcp_callbacks;
486 fsm_init(&ipcp_fsm[unit]);
488 memset(wo, 0, sizeof(*wo));
489 memset(ao, 0, sizeof(*ao));
493 wo->vj_protocol = IPCP_VJ_COMP;
494 wo->maxslotindex = MAX_STATES - 1; /* really max index */
498 /* max slots and slot-id compression are currently hardwired in */
499 /* ppp_if.c to 16 and 1, this needs to be changed (among other */
504 ao->maxslotindex = MAX_STATES - 1;
508 * XXX These control whether the user may use the proxyarp
509 * and defaultroute options.
512 ao->default_route = 1;
517 * ipcp_open - IPCP is allowed to come up.
523 fsm_open(&ipcp_fsm[unit]);
528 * ipcp_close - Take IPCP down.
531 ipcp_close(unit, reason)
535 fsm_close(&ipcp_fsm[unit], reason);
540 * ipcp_lowerup - The lower layer is up.
546 fsm_lowerup(&ipcp_fsm[unit]);
551 * ipcp_lowerdown - The lower layer is down.
557 fsm_lowerdown(&ipcp_fsm[unit]);
562 * ipcp_input - Input IPCP packet.
565 ipcp_input(unit, p, len)
570 fsm_input(&ipcp_fsm[unit], p, len);
575 * ipcp_protrej - A Protocol-Reject was received for IPCP.
577 * Pretend the lower layer went down, so we shut up.
583 fsm_lowerdown(&ipcp_fsm[unit]);
588 * ipcp_resetci - Reset our CI.
589 * Called by fsm_sconfreq, Send Configure Request.
595 ipcp_options *wo = &ipcp_wantoptions[f->unit];
596 ipcp_options *go = &ipcp_gotoptions[f->unit];
598 wo->req_addr = wo->neg_addr && ipcp_allowoptions[f->unit].neg_addr;
599 if (wo->ouraddr == 0)
600 wo->accept_local = 1;
601 if (wo->hisaddr == 0)
602 wo->accept_remote = 1;
603 wo->req_dns1 = usepeerdns; /* Request DNS addresses from the peer */
604 wo->req_dns2 = usepeerdns;
609 ip_choose_hook(&wo->hisaddr);
614 * ipcp_cilen - Return length of our CI.
615 * Called by fsm_sconfreq, Send Configure Request.
621 ipcp_options *go = &ipcp_gotoptions[f->unit];
622 ipcp_options *wo = &ipcp_wantoptions[f->unit];
623 ipcp_options *ho = &ipcp_hisoptions[f->unit];
625 #define LENCIVJ(neg, old) (neg ? (old? CILEN_COMPRESS : CILEN_VJ) : 0)
626 #define LENCIADDR(neg, old) (neg ? (old? CILEN_ADDRS : CILEN_ADDR) : 0)
627 #define LENCIDNS(neg) (neg ? (CILEN_ADDR) : 0)
630 * First see if we want to change our options to the old
631 * forms because we have received old forms from the peer.
633 if (wo->neg_addr && !go->neg_addr && !go->old_addrs) {
634 /* use the old style of address negotiation */
638 if (wo->neg_vj && !go->neg_vj && !go->old_vj) {
639 /* try an older style of VJ negotiation */
640 /* use the old style only if the peer did */
641 if (ho->neg_vj && ho->old_vj) {
644 go->vj_protocol = ho->vj_protocol;
648 return (LENCIADDR(go->neg_addr, go->old_addrs) +
649 LENCIVJ(go->neg_vj, go->old_vj) +
650 LENCIDNS(go->req_dns1) +
651 LENCIDNS(go->req_dns2)) ;
656 * ipcp_addci - Add our desired CIs to a packet.
657 * Called by fsm_sconfreq, Send Configure Request.
660 ipcp_addci(f, ucp, lenp)
665 ipcp_options *go = &ipcp_gotoptions[f->unit];
668 #define ADDCIVJ(opt, neg, val, old, maxslotindex, cflag) \
670 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
671 if (len >= vjlen) { \
673 PUTCHAR(vjlen, ucp); \
674 PUTSHORT(val, ucp); \
676 PUTCHAR(maxslotindex, ucp); \
677 PUTCHAR(cflag, ucp); \
684 #define ADDCIADDR(opt, neg, old, val1, val2) \
686 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
687 if (len >= addrlen) { \
690 PUTCHAR(addrlen, ucp); \
702 #define ADDCIDNS(opt, neg, addr) \
704 if (len >= CILEN_ADDR) { \
707 PUTCHAR(CILEN_ADDR, ucp); \
715 ADDCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
716 go->old_addrs, go->ouraddr, go->hisaddr);
718 ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
719 go->maxslotindex, go->cflag);
721 ADDCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
723 ADDCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
730 * ipcp_ackci - Ack our CIs.
731 * Called by fsm_rconfack, Receive Configure ACK.
738 ipcp_ackci(f, p, len)
743 ipcp_options *go = &ipcp_gotoptions[f->unit];
744 u_short cilen, citype, cishort;
746 u_char cimaxslotindex, cicflag;
749 * CIs must be in exactly the same order that we sent...
750 * Check packet length and CI length at each step.
751 * If we find any deviations, then this packet is bad.
754 #define ACKCIVJ(opt, neg, val, old, maxslotindex, cflag) \
756 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
757 if ((len -= vjlen) < 0) \
759 GETCHAR(citype, p); \
761 if (cilen != vjlen || \
764 GETSHORT(cishort, p); \
765 if (cishort != val) \
768 GETCHAR(cimaxslotindex, p); \
769 if (cimaxslotindex != maxslotindex) \
771 GETCHAR(cicflag, p); \
772 if (cicflag != cflag) \
777 #define ACKCIADDR(opt, neg, old, val1, val2) \
779 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
781 if ((len -= addrlen) < 0) \
783 GETCHAR(citype, p); \
785 if (cilen != addrlen || \
790 if (val1 != cilong) \
795 if (val2 != cilong) \
800 #define ACKCIDNS(opt, neg, addr) \
803 if ((len -= CILEN_ADDR) < 0) \
805 GETCHAR(citype, p); \
807 if (cilen != CILEN_ADDR || citype != opt) \
811 if (addr != cilong) \
815 ACKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
816 go->old_addrs, go->ouraddr, go->hisaddr);
818 ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
819 go->maxslotindex, go->cflag);
821 ACKCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
823 ACKCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
826 * If there are any remaining CIs, then this packet is bad.
833 IPCPDEBUG(("ipcp_ackci: received bad Ack!"));
838 * ipcp_nakci - Peer has sent a NAK for some of our CIs.
839 * This should not modify any state if the Nak is bad
840 * or if IPCP is in the OPENED state.
841 * Calback from fsm_rconfnakrej - Receive Configure-Nak or Configure-Reject.
848 ipcp_nakci(f, p, len)
853 ipcp_options *go = &ipcp_gotoptions[f->unit];
854 u_char cimaxslotindex, cicflag;
855 u_char citype, cilen, *next;
857 u_int32_t ciaddr1, ciaddr2, l, cidnsaddr;
858 ipcp_options no; /* options we've seen Naks for */
859 ipcp_options try; /* options to request next time */
861 BZERO(&no, sizeof(no));
865 * Any Nak'd CIs must be in exactly the same order that we sent.
866 * Check packet length and CI length at each step.
867 * If we find any deviations, then this packet is bad.
869 #define NAKCIADDR(opt, neg, old, code) \
871 len >= (cilen = (old? CILEN_ADDRS: CILEN_ADDR)) && \
877 ciaddr1 = htonl(l); \
880 ciaddr2 = htonl(l); \
888 #define NAKCIVJ(opt, neg, code) \
890 ((cilen = p[1]) == CILEN_COMPRESS || cilen == CILEN_VJ) && \
895 GETSHORT(cishort, p); \
900 #define NAKCIDNS(opt, neg, code) \
902 ((cilen = p[1]) == CILEN_ADDR) && \
908 cidnsaddr = htonl(l); \
914 * Accept the peer's idea of {our,his} address, if different
915 * from our idea, only if the accept_{local,remote} flag is set.
917 NAKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr, go->old_addrs,
918 if (go->accept_local && ciaddr1) { /* Do we know our address? */
919 try.ouraddr = ciaddr1;
921 if (go->accept_remote && ciaddr2) { /* Does he know his? */
922 try.hisaddr = ciaddr2;
927 * Accept the peer's value of maxslotindex provided that it
928 * is less than what we asked for. Turn off slot-ID compression
929 * if the peer wants. Send old-style compress-type option if
932 NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
933 if (cilen == CILEN_VJ) {
934 GETCHAR(cimaxslotindex, p);
936 if (cishort == IPCP_VJ_COMP) {
938 if (cimaxslotindex < go->maxslotindex)
939 try.maxslotindex = cimaxslotindex;
946 if (cishort == IPCP_VJ_COMP || cishort == IPCP_VJ_COMP_OLD) {
948 try.vj_protocol = cishort;
955 NAKCIDNS(CI_MS_DNS1, req_dns1,
956 try.dnsaddr[0] = cidnsaddr;
959 NAKCIDNS(CI_MS_DNS2, req_dns2,
960 try.dnsaddr[1] = cidnsaddr;
964 * There may be remaining CIs, if the peer is requesting negotiation
965 * on an option that we didn't include in our request packet.
966 * If they want to negotiate about IP addresses, we comply.
967 * If they want us to ask for compression, we refuse.
969 while (len > CILEN_VOID) {
972 if( (len -= cilen) < 0 )
974 next = p + cilen - 2;
977 case CI_COMPRESSTYPE:
978 if (go->neg_vj || no.neg_vj ||
979 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS))
984 if ((go->neg_addr && go->old_addrs) || no.old_addrs
985 || cilen != CILEN_ADDRS)
991 if (ciaddr1 && go->accept_local)
992 try.ouraddr = ciaddr1;
995 if (ciaddr2 && go->accept_remote)
996 try.hisaddr = ciaddr2;
1000 if (go->neg_addr || no.neg_addr || cilen != CILEN_ADDR)
1005 if (ciaddr1 && go->accept_local)
1006 try.ouraddr = ciaddr1;
1007 if (try.ouraddr != 0)
1016 * OK, the Nak is good. Now we can update state.
1017 * If there are any remaining options, we ignore them.
1019 if (f->state != OPENED)
1025 IPCPDEBUG(("ipcp_nakci: received bad Nak!"));
1031 * ipcp_rejci - Reject some of our CIs.
1032 * Callback from fsm_rconfnakrej.
1035 ipcp_rejci(f, p, len)
1040 ipcp_options *go = &ipcp_gotoptions[f->unit];
1041 u_char cimaxslotindex, ciflag, cilen;
1044 ipcp_options try; /* options to request next time */
1048 * Any Rejected CIs must be in exactly the same order that we sent.
1049 * Check packet length and CI length at each step.
1050 * If we find any deviations, then this packet is bad.
1052 #define REJCIADDR(opt, neg, old, val1, val2) \
1054 len >= (cilen = old? CILEN_ADDRS: CILEN_ADDR) && \
1061 cilong = htonl(l); \
1062 /* Check rejected value. */ \
1063 if (cilong != val1) \
1067 cilong = htonl(l); \
1068 /* Check rejected value. */ \
1069 if (cilong != val2) \
1075 #define REJCIVJ(opt, neg, val, old, maxslot, cflag) \
1077 p[1] == (old? CILEN_COMPRESS : CILEN_VJ) && \
1082 GETSHORT(cishort, p); \
1083 /* Check rejected value. */ \
1084 if (cishort != val) \
1087 GETCHAR(cimaxslotindex, p); \
1088 if (cimaxslotindex != maxslot) \
1090 GETCHAR(ciflag, p); \
1091 if (ciflag != cflag) \
1097 #define REJCIDNS(opt, neg, dnsaddr) \
1099 ((cilen = p[1]) == CILEN_ADDR) && \
1106 cilong = htonl(l); \
1107 /* Check rejected value. */ \
1108 if (cilong != dnsaddr) \
1114 REJCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr,
1115 go->old_addrs, go->ouraddr, go->hisaddr);
1117 REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol, go->old_vj,
1118 go->maxslotindex, go->cflag);
1120 REJCIDNS(CI_MS_DNS1, req_dns1, go->dnsaddr[0]);
1122 REJCIDNS(CI_MS_DNS2, req_dns2, go->dnsaddr[1]);
1125 * If there are any remaining CIs, then this packet is bad.
1130 * Now we can update state.
1132 if (f->state != OPENED)
1137 IPCPDEBUG(("ipcp_rejci: received bad Reject!"));
1143 * ipcp_reqci - Check the peer's requested CIs and send appropriate response.
1144 * Callback from fsm_rconfreq, Receive Configure Request
1146 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
1147 * appropriately. If reject_if_disagree is non-zero, doesn't return
1148 * CONFNAK; returns CONFREJ if it can't return CONFACK.
1151 ipcp_reqci(f, inp, len, reject_if_disagree)
1153 u_char *inp; /* Requested CIs */
1154 int *len; /* Length of requested CIs */
1155 int reject_if_disagree;
1157 ipcp_options *wo = &ipcp_wantoptions[f->unit];
1158 ipcp_options *ho = &ipcp_hisoptions[f->unit];
1159 ipcp_options *ao = &ipcp_allowoptions[f->unit];
1160 ipcp_options *go = &ipcp_gotoptions[f->unit];
1161 u_char *cip, *next; /* Pointer to current and next CIs */
1162 u_short cilen, citype; /* Parsed len, type */
1163 u_short cishort; /* Parsed short value */
1164 u_int32_t tl, ciaddr1, ciaddr2;/* Parsed address values */
1165 int rc = CONFACK; /* Final packet return code */
1166 int orc; /* Individual option return code */
1167 u_char *p; /* Pointer to next char to parse */
1168 u_char *ucp = inp; /* Pointer to current output char */
1169 int l = *len; /* Length left */
1170 u_char maxslotindex, cflag;
1174 * Reset all his options.
1176 BZERO(ho, sizeof(*ho));
1179 * Process all his options.
1183 orc = CONFACK; /* Assume success */
1184 cip = p = next; /* Remember begining of CI */
1185 if (l < 2 || /* Not enough data for CI header or */
1186 p[1] < 2 || /* CI length too small or */
1187 p[1] > l) { /* CI length too big? */
1188 IPCPDEBUG(("ipcp_reqci: bad CI length!"));
1189 orc = CONFREJ; /* Reject bad CI */
1190 cilen = l; /* Reject till end of packet */
1191 l = 0; /* Don't loop again */
1194 GETCHAR(citype, p); /* Parse CI type */
1195 GETCHAR(cilen, p); /* Parse CI length */
1196 l -= cilen; /* Adjust remaining length */
1197 next += cilen; /* Step to next CI */
1199 switch (citype) { /* Check CI type */
1201 if (!ao->neg_addr ||
1202 cilen != CILEN_ADDRS) { /* Check CI length */
1203 orc = CONFREJ; /* Reject CI */
1208 * If he has no address, or if we both have his address but
1209 * disagree about it, then NAK it with our idea.
1210 * In particular, if we don't know his address, but he does,
1213 GETLONG(tl, p); /* Parse source address (his) */
1214 ciaddr1 = htonl(tl);
1215 if (ciaddr1 != wo->hisaddr
1216 && (ciaddr1 == 0 || !wo->accept_remote)) {
1218 if (!reject_if_disagree) {
1219 DECPTR(sizeof(u_int32_t), p);
1220 tl = ntohl(wo->hisaddr);
1223 } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
1225 * If neither we nor he knows his address, reject the option.
1228 wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
1233 * If he doesn't know our address, or if we both have our address
1234 * but disagree about it, then NAK it with our idea.
1236 GETLONG(tl, p); /* Parse desination address (ours) */
1237 ciaddr2 = htonl(tl);
1238 if (ciaddr2 != wo->ouraddr) {
1239 if (ciaddr2 == 0 || !wo->accept_local) {
1241 if (!reject_if_disagree) {
1242 DECPTR(sizeof(u_int32_t), p);
1243 tl = ntohl(wo->ouraddr);
1247 go->ouraddr = ciaddr2; /* accept peer's idea */
1253 ho->hisaddr = ciaddr1;
1254 ho->ouraddr = ciaddr2;
1258 if (!ao->neg_addr ||
1259 cilen != CILEN_ADDR) { /* Check CI length */
1260 orc = CONFREJ; /* Reject CI */
1265 * If he has no address, or if we both have his address but
1266 * disagree about it, then NAK it with our idea.
1267 * In particular, if we don't know his address, but he does,
1270 GETLONG(tl, p); /* Parse source address (his) */
1271 ciaddr1 = htonl(tl);
1272 if (ciaddr1 != wo->hisaddr
1273 && (ciaddr1 == 0 || !wo->accept_remote)) {
1275 if (!reject_if_disagree) {
1276 DECPTR(sizeof(u_int32_t), p);
1277 tl = ntohl(wo->hisaddr);
1280 } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
1282 * Don't ACK an address of 0.0.0.0 - reject it instead.
1285 wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
1290 ho->hisaddr = ciaddr1;
1295 /* Microsoft primary or secondary DNS request */
1296 d = citype == CI_MS_DNS2;
1298 /* If we do not have a DNS address then we cannot send it */
1299 if (ao->dnsaddr[d] == 0 ||
1300 cilen != CILEN_ADDR) { /* Check CI length */
1301 orc = CONFREJ; /* Reject CI */
1305 if (htonl(tl) != ao->dnsaddr[d]) {
1306 DECPTR(sizeof(u_int32_t), p);
1307 tl = ntohl(ao->dnsaddr[d]);
1315 /* Microsoft primary or secondary WINS request */
1316 d = citype == CI_MS_WINS2;
1318 /* If we do not have a DNS address then we cannot send it */
1319 if (ao->winsaddr[d] == 0 ||
1320 cilen != CILEN_ADDR) { /* Check CI length */
1321 orc = CONFREJ; /* Reject CI */
1325 if (htonl(tl) != ao->winsaddr[d]) {
1326 DECPTR(sizeof(u_int32_t), p);
1327 tl = ntohl(ao->winsaddr[d]);
1333 case CI_COMPRESSTYPE:
1335 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS)) {
1339 GETSHORT(cishort, p);
1341 if (!(cishort == IPCP_VJ_COMP ||
1342 (cishort == IPCP_VJ_COMP_OLD && cilen == CILEN_COMPRESS))) {
1348 ho->vj_protocol = cishort;
1349 if (cilen == CILEN_VJ) {
1350 GETCHAR(maxslotindex, p);
1351 if (maxslotindex > ao->maxslotindex) {
1353 if (!reject_if_disagree){
1355 PUTCHAR(ao->maxslotindex, p);
1359 if (cflag && !ao->cflag) {
1361 if (!reject_if_disagree){
1363 PUTCHAR(wo->cflag, p);
1366 ho->maxslotindex = maxslotindex;
1370 ho->maxslotindex = MAX_STATES - 1;
1380 if (orc == CONFACK && /* Good CI */
1381 rc != CONFACK) /* but prior CI wasnt? */
1382 continue; /* Don't send this one */
1384 if (orc == CONFNAK) { /* Nak this CI? */
1385 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1386 orc = CONFREJ; /* Get tough if so */
1388 if (rc == CONFREJ) /* Rejecting prior CI? */
1389 continue; /* Don't send this one */
1390 if (rc == CONFACK) { /* Ack'd all prior CIs? */
1391 rc = CONFNAK; /* Not anymore... */
1392 ucp = inp; /* Backup */
1397 if (orc == CONFREJ && /* Reject this CI */
1398 rc != CONFREJ) { /* but no prior ones? */
1400 ucp = inp; /* Backup */
1403 /* Need to move CI? */
1405 BCOPY(cip, ucp, cilen); /* Move it */
1407 /* Update output pointer */
1412 * If we aren't rejecting this packet, and we want to negotiate
1413 * their address, and they didn't send their address, then we
1414 * send a NAK with a CI_ADDR option appended. We assume the
1415 * input buffer is long enough that we can append the extra
1418 if (rc != CONFREJ && !ho->neg_addr &&
1419 wo->req_addr && !reject_if_disagree) {
1420 if (rc == CONFACK) {
1422 ucp = inp; /* reset pointer */
1423 wo->req_addr = 0; /* don't ask again */
1425 PUTCHAR(CI_ADDR, ucp);
1426 PUTCHAR(CILEN_ADDR, ucp);
1427 tl = ntohl(wo->hisaddr);
1431 *len = ucp - inp; /* Compute output length */
1432 IPCPDEBUG(("ipcp: returning Configure-%s", CODENAME(rc)));
1433 return (rc); /* Return final code */
1438 * ip_check_options - check that any IP-related options are OK,
1439 * and assign appropriate defaults.
1446 ipcp_options *wo = &ipcp_wantoptions[0];
1449 * Default our local IP address based on our hostname.
1450 * If local IP address already given, don't bother.
1452 if (wo->ouraddr == 0 && !disable_defaultip) {
1454 * Look up our hostname (possibly with domain name appended)
1455 * and take the first IP address as our local IP address.
1456 * If there isn't an IP address for our hostname, too bad.
1458 wo->accept_local = 1; /* don't insist on this default value */
1459 if ((hp = gethostbyname(hostname)) != NULL) {
1460 local = *(u_int32_t *)hp->h_addr;
1461 if (local != 0 && !bad_ip_adrs(local))
1462 wo->ouraddr = local;
1465 ask_for_local = wo->ouraddr != 0 || !disable_defaultip;
1470 * ip_demand_conf - configure the interface as though
1471 * IPCP were up, for use with dial-on-demand.
1477 ipcp_options *wo = &ipcp_wantoptions[u];
1479 if (wo->hisaddr == 0) {
1480 /* make up an arbitrary address for the peer */
1481 wo->hisaddr = htonl(0x0a707070 + ifunit);
1482 wo->accept_remote = 1;
1484 if (wo->ouraddr == 0) {
1485 /* make up an arbitrary address for us */
1486 wo->ouraddr = htonl(0x0a404040 + ifunit);
1487 wo->accept_local = 1;
1488 ask_for_local = 0; /* don't tell the peer this address */
1490 if (!sifaddr(u, wo->ouraddr, wo->hisaddr, GetMask(wo->ouraddr)))
1494 if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE))
1496 if (wo->default_route)
1497 if (sifdefaultroute(u, wo->ouraddr, wo->hisaddr))
1498 default_route_set[u] = 1;
1500 if (sifproxyarp(u, wo->hisaddr))
1501 proxy_arp_set[u] = 1;
1503 notice("local IP address %I", wo->ouraddr);
1504 notice("remote IP address %I", wo->hisaddr);
1511 * ipcp_up - IPCP has come UP.
1513 * Configure the IP network interface appropriately and bring it up.
1520 ipcp_options *ho = &ipcp_hisoptions[f->unit];
1521 ipcp_options *go = &ipcp_gotoptions[f->unit];
1522 ipcp_options *wo = &ipcp_wantoptions[f->unit];
1524 IPCPDEBUG(("ipcp: up"));
1527 * We must have a non-zero IP address for both ends of the link.
1530 ho->hisaddr = wo->hisaddr;
1532 if (go->ouraddr == 0) {
1533 error("Could not determine local IP address");
1534 ipcp_close(f->unit, "Could not determine local IP address");
1537 if (ho->hisaddr == 0) {
1538 ho->hisaddr = htonl(0x0a404040 + ifunit);
1539 warn("Could not determine remote IP address: defaulting to %I",
1542 script_setenv("IPLOCAL", ip_ntoa(go->ouraddr), 0);
1543 script_setenv("IPREMOTE", ip_ntoa(ho->hisaddr), 1);
1545 if (usepeerdns && (go->dnsaddr[0] || go->dnsaddr[1])) {
1546 script_setenv("USEPEERDNS", "1", 0);
1548 script_setenv("DNS1", ip_ntoa(go->dnsaddr[0]), 0);
1550 script_setenv("DNS2", ip_ntoa(go->dnsaddr[1]), 0);
1551 create_resolv(go->dnsaddr[0], go->dnsaddr[1]);
1555 * Check that the peer is allowed to use the IP address it wants.
1557 if (!auth_ip_addr(f->unit, ho->hisaddr)) {
1558 error("Peer is not authorized to use remote address %I", ho->hisaddr);
1559 ipcp_close(f->unit, "Unauthorized remote IP address");
1563 /* set tcp compression */
1564 sifvjcomp(f->unit, ho->neg_vj, ho->cflag, ho->maxslotindex);
1567 * If we are doing dial-on-demand, the interface is already
1568 * configured, so we put out any saved-up packets, then set the
1569 * interface to pass IP packets.
1572 if (go->ouraddr != wo->ouraddr || ho->hisaddr != wo->hisaddr) {
1573 ipcp_clear_addrs(f->unit, wo->ouraddr, wo->hisaddr);
1574 if (go->ouraddr != wo->ouraddr) {
1575 warn("Local IP address changed to %I", go->ouraddr);
1576 script_setenv("OLDIPLOCAL", ip_ntoa(wo->ouraddr), 0);
1577 wo->ouraddr = go->ouraddr;
1579 script_unsetenv("OLDIPLOCAL");
1580 if (ho->hisaddr != wo->hisaddr) {
1581 warn("Remote IP address changed to %I", ho->hisaddr);
1582 script_setenv("OLDIPREMOTE", ip_ntoa(wo->hisaddr), 0);
1583 wo->hisaddr = ho->hisaddr;
1585 script_unsetenv("OLDIPREMOTE");
1587 /* Set the interface to the new addresses */
1588 mask = GetMask(go->ouraddr);
1589 if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
1591 warn("Interface configuration failed");
1592 ipcp_close(f->unit, "Interface configuration failed");
1596 /* assign a default route through the interface if required */
1597 if (ipcp_wantoptions[f->unit].default_route)
1598 if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
1599 default_route_set[f->unit] = 1;
1601 /* Make a proxy ARP entry if requested. */
1602 if (ipcp_wantoptions[f->unit].proxy_arp)
1603 if (sifproxyarp(f->unit, ho->hisaddr))
1604 proxy_arp_set[f->unit] = 1;
1607 demand_rexmit(PPP_IP);
1608 sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
1612 * Set IP addresses and (if specified) netmask.
1614 mask = GetMask(go->ouraddr);
1616 #if !(defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1617 if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
1619 warn("Interface configuration failed");
1620 ipcp_close(f->unit, "Interface configuration failed");
1625 /* bring the interface up for IP */
1626 if (!sifup(f->unit)) {
1628 warn("Interface failed to come up");
1629 ipcp_close(f->unit, "Interface configuration failed");
1633 #if (defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1634 if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
1636 warn("Interface configuration failed");
1637 ipcp_close(f->unit, "Interface configuration failed");
1641 sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
1643 /* assign a default route through the interface if required */
1644 if (ipcp_wantoptions[f->unit].default_route)
1645 if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
1646 default_route_set[f->unit] = 1;
1648 /* Make a proxy ARP entry if requested. */
1649 if (ipcp_wantoptions[f->unit].proxy_arp)
1650 if (sifproxyarp(f->unit, ho->hisaddr))
1651 proxy_arp_set[f->unit] = 1;
1653 ipcp_wantoptions[0].ouraddr = go->ouraddr;
1655 notice("local IP address %I", go->ouraddr);
1656 notice("remote IP address %I", ho->hisaddr);
1658 notice("primary DNS address %I", go->dnsaddr[0]);
1660 notice("secondary DNS address %I", go->dnsaddr[1]);
1663 np_up(f->unit, PPP_IP);
1670 * Execute the ip-up script, like this:
1671 * /etc/ppp/ip-up interface tty speed local-IP remote-IP
1673 if (ipcp_script_state == s_down && ipcp_script_pid == 0) {
1674 ipcp_script_state = s_up;
1675 ipcp_script(_PATH_IPUP);
1681 * ipcp_down - IPCP has gone DOWN.
1683 * Take the IP network interface down, clear its addresses
1684 * and delete routes through it.
1690 IPCPDEBUG(("ipcp: down"));
1691 /* XXX a bit IPv4-centric here, we only need to get the stats
1692 * before the interface is marked down. */
1693 update_link_stats(f->unit);
1698 np_down(f->unit, PPP_IP);
1700 sifvjcomp(f->unit, 0, 0, 0);
1703 * If we are doing dial-on-demand, set the interface
1704 * to queue up outgoing packets (for now).
1707 sifnpmode(f->unit, PPP_IP, NPMODE_QUEUE);
1709 sifnpmode(f->unit, PPP_IP, NPMODE_DROP);
1711 ipcp_clear_addrs(f->unit, ipcp_gotoptions[f->unit].ouraddr,
1712 ipcp_hisoptions[f->unit].hisaddr);
1715 /* Execute the ip-down script */
1716 if (ipcp_script_state == s_up && ipcp_script_pid == 0) {
1717 ipcp_script_state = s_down;
1718 ipcp_script(_PATH_IPDOWN);
1724 * ipcp_clear_addrs() - clear the interface addresses, routes,
1725 * proxy arp entries, etc.
1728 ipcp_clear_addrs(unit, ouraddr, hisaddr)
1730 u_int32_t ouraddr; /* local address */
1731 u_int32_t hisaddr; /* remote address */
1733 if (proxy_arp_set[unit]) {
1734 cifproxyarp(unit, hisaddr);
1735 proxy_arp_set[unit] = 0;
1737 if (default_route_set[unit]) {
1738 cifdefaultroute(unit, ouraddr, hisaddr);
1739 default_route_set[unit] = 0;
1741 cifaddr(unit, ouraddr, hisaddr);
1746 * ipcp_finished - possibly shut down the lower layers.
1752 np_finished(f->unit, PPP_IP);
1757 * ipcp_script_done - called when the ip-up or ip-down script
1761 ipcp_script_done(arg)
1764 ipcp_script_pid = 0;
1765 switch (ipcp_script_state) {
1767 if (ipcp_fsm[0].state != OPENED) {
1768 ipcp_script_state = s_down;
1769 ipcp_script(_PATH_IPDOWN);
1773 if (ipcp_fsm[0].state == OPENED) {
1774 ipcp_script_state = s_up;
1775 ipcp_script(_PATH_IPUP);
1783 * ipcp_script - Execute a script with arguments
1784 * interface-name tty-name speed local-IP remote-IP.
1790 char strspeed[32], strlocal[32], strremote[32];
1793 slprintf(strspeed, sizeof(strspeed), "%d", baud_rate);
1794 slprintf(strlocal, sizeof(strlocal), "%I", ipcp_gotoptions[0].ouraddr);
1795 slprintf(strremote, sizeof(strremote), "%I", ipcp_hisoptions[0].hisaddr);
1802 argv[5] = strremote;
1805 ipcp_script_pid = run_program(script, argv, 0, ipcp_script_done, NULL);
1809 * create_resolv - create the replacement resolv.conf file
1812 create_resolv(peerdns1, peerdns2)
1813 u_int32_t peerdns1, peerdns2;
1817 f = fopen(_PATH_RESOLV, "w");
1819 error("Failed to create %s: %m", _PATH_RESOLV);
1824 fprintf(f, "nameserver %s\n", ip_ntoa(peerdns1));
1827 fprintf(f, "nameserver %s\n", ip_ntoa(peerdns2));
1830 error("Write failed to %s: %m", _PATH_RESOLV);
1836 * ipcp_printpkt - print the contents of an IPCP packet.
1838 static char *ipcp_codenames[] = {
1839 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1840 "TermReq", "TermAck", "CodeRej"
1844 ipcp_printpkt(p, plen, printer, arg)
1847 void (*printer) __P((void *, char *, ...));
1850 int code, id, len, olen;
1851 u_char *pstart, *optend;
1855 if (plen < HEADERLEN)
1861 if (len < HEADERLEN || len > plen)
1864 if (code >= 1 && code <= sizeof(ipcp_codenames) / sizeof(char *))
1865 printer(arg, " %s", ipcp_codenames[code-1]);
1867 printer(arg, " code=0x%x", code);
1868 printer(arg, " id=0x%x", id);
1875 /* print option list */
1880 if (olen < 2 || olen > len) {
1888 if (olen == CILEN_ADDRS) {
1891 printer(arg, "addrs %I", htonl(cilong));
1893 printer(arg, " %I", htonl(cilong));
1896 case CI_COMPRESSTYPE:
1897 if (olen >= CILEN_COMPRESS) {
1899 GETSHORT(cishort, p);
1900 printer(arg, "compress ");
1905 case IPCP_VJ_COMP_OLD:
1906 printer(arg, "old-VJ");
1909 printer(arg, "0x%x", cishort);
1914 if (olen == CILEN_ADDR) {
1917 printer(arg, "addr %I", htonl(cilong));
1924 printer(arg, "ms-dns%d %I", code - CI_MS_DNS1 + 1,
1931 printer(arg, "ms-wins %I", htonl(cilong));
1934 while (p < optend) {
1936 printer(arg, " %.2x", code);
1944 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1946 print_string((char *)p, len, printer, arg);
1953 /* print the rest of the bytes in the packet */
1954 for (; len > 0; --len) {
1956 printer(arg, " %.2x", code);
1963 * ip_active_pkt - see if this IP packet is worth bringing the link up for.
1964 * We don't bring the link up for IP fragments or for TCP FIN packets
1967 #define IP_HDRLEN 20 /* bytes */
1968 #define IP_OFFMASK 0x1fff
1969 #define IPPROTO_TCP 6
1970 #define TCP_HDRLEN 20
1974 * We use these macros because the IP header may be at an odd address,
1975 * and some compilers might use word loads to get th_off or ip_hl.
1978 #define net_short(x) (((x)[0] << 8) + (x)[1])
1979 #define get_iphl(x) (((unsigned char *)(x))[0] & 0xF)
1980 #define get_ipoff(x) net_short((unsigned char *)(x) + 6)
1981 #define get_ipproto(x) (((unsigned char *)(x))[9])
1982 #define get_tcpoff(x) (((unsigned char *)(x))[12] >> 4)
1983 #define get_tcpflags(x) (((unsigned char *)(x))[13])
1986 ip_active_pkt(pkt, len)
1995 if (len < IP_HDRLEN)
1997 if ((get_ipoff(pkt) & IP_OFFMASK) != 0)
1999 if (get_ipproto(pkt) != IPPROTO_TCP)
2001 hlen = get_iphl(pkt) * 4;
2002 if (len < hlen + TCP_HDRLEN)
2005 if ((get_tcpflags(tcp) & TH_FIN) != 0 && len == hlen + get_tcpoff(tcp) * 4)