Deleted Added
full compact
1/*
2 * Synchronous PPP/Cisco link level subroutines.
2 * Synchronous PPP/Cisco/Frame Relay link level subroutines.
3 * Keepalive protocol implemented in both Cisco and PPP modes.
4 *
5 * Copyright (C) 1994-1996 Cronyx Engineering Ltd.
5 * Copyright (C) 1994-2000 Cronyx Engineering.
6 * Author: Serge Vakulenko, <vak@cronyx.ru>
7 *
8 * Heavily revamped to conform to RFC 1661.
9 * Copyright (C) 1997, 2001 Joerg Wunsch.
10 *
11 * This software is distributed with NO WARRANTIES, not even the implied
12 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 * Authors grant any other persons or organisations permission to use
15 * or modify this software as long as this message is kept with the software,
16 * all derivative works or modified versions.
17 *
18 * From: Version 2.4, Thu Apr 30 17:17:21 MSD 1997
19 *
20 * $FreeBSD: head/sys/net/if_spppsubr.c 138855 2004-12-14 18:18:54Z rik $
20 * $FreeBSD: head/sys/net/if_spppsubr.c 139365 2004-12-28 00:07:57Z rik $
21 */
22
23#include <sys/param.h>
24
25#if defined(__FreeBSD__) && __FreeBSD__ >= 3
26#include "opt_inet.h"
27#include "opt_inet6.h"
28#include "opt_ipx.h"

--- 375 unchanged lines hidden (view full) ---

404static const char *sppp_ipv6cp_opt_name(u_char opt);
405#endif
406static const char *sppp_lcp_opt_name(u_char opt);
407static const char *sppp_phase_name(enum ppp_phase phase);
408static const char *sppp_proto_name(u_short proto);
409static const char *sppp_state_name(int state);
410static int sppp_params(struct sppp *sp, u_long cmd, void *data);
411static int sppp_strnlen(u_char *p, int max);
412static void sppp_get_ip_addrs(struct sppp *sp, u_long *src, u_long *dst,
413 u_long *srcmask);
412static void sppp_keepalive(void *dummy);
413static void sppp_phase_network(struct sppp *sp);
414static void sppp_print_bytes(const u_char *p, u_short len);
415static void sppp_print_string(const char *p, u_short len);
416static void sppp_qflush(struct ifqueue *ifq);
417static void sppp_set_ip_addr(struct sppp *sp, u_long src);
418#ifdef INET6
419static void sppp_get_ip6_addrs(struct sppp *sp, struct in6_addr *src,

--- 124 unchanged lines hidden (view full) ---

544 m_freem (m);
545 SPPP_UNLOCK(sp);
546 drop2:
547 ++ifp->if_ierrors;
548 ++ifp->if_iqdrops;
549 return;
550 }
551
552 if (sp->pp_mode == PP_FR) {
553 sppp_fr_input (sp, m);
554 SPPP_UNLOCK(sp);
555 return;
556 }
557
558 /* Get PPP header. */
559 h = mtod (m, struct ppp_header*);
560 m_adj (m, PPP_HEADER_LEN);
561
562 switch (h->address) {
563 case PPP_ALLSTATIONS:
564 if (h->control != PPP_UI)
565 goto invalid;

--- 320 unchanged lines hidden (view full) ---

886 else if (INTERACTIVE (ntohs (tcp->th_sport)))
887 ifq = &sp->pp_fastq;
888 else if (INTERACTIVE (ntohs (tcp->th_dport)))
889 ifq = &sp->pp_fastq;
890
891 /*
892 * Do IP Header compression
893 */
890 if (sp->pp_mode != IFF_CISCO &&
894 if (sp->pp_mode != IFF_CISCO && sp->pp_mode != PP_FR &&
895 (sp->ipcp.flags & IPCP_VJ) && ip->ip_p == IPPROTO_TCP)
896 switch (sl_compress_tcp(m, ip, sp->pp_comp,
897 sp->ipcp.compress_cid)) {
898 case TYPE_COMPRESSED_TCP:
899 ipproto = PPP_VJ_COMP;
900 break;
901 case TYPE_UNCOMPRESSED_TCP:
902 ipproto = PPP_VJ_UCOMP;

--- 11 unchanged lines hidden (view full) ---

914#endif
915
916#ifdef INET6
917 if (dst->sa_family == AF_INET6) {
918 /* XXX do something tricky here? */
919 }
920#endif
921
922 if (sp->pp_mode == PP_FR) {
923 /* Add frame relay header. */
924 m = sppp_fr_header (sp, m, dst->sa_family);
925 if (! m)
926 goto nobufs;
927 goto out;
928 }
929
930 /*
931 * Prepend general data packet PPP header. For now, IP only.
932 */
933 M_PREPEND (m, PPP_HEADER_LEN, M_DONTWAIT);
934 if (! m) {
923 if (debug)
935nobufs: if (debug)
936 log(LOG_DEBUG, SPP_FMT "no memory for transmit header\n",
937 SPP_ARGS(ifp));
938 ++ifp->if_oerrors;
939 SPPP_UNLOCK(sp);
940 splx (s);
941 return (ENOBUFS);
942 }
943 /*

--- 63 unchanged lines hidden (view full) ---

1007 splx (s);
1008 return (EAFNOSUPPORT);
1009 }
1010
1011 /*
1012 * Queue message on interface, and start output if interface
1013 * not yet active.
1014 */
1015out:
1016 if (ifq != NULL)
1017 error = !(IF_HANDOFF_ADJ(ifq, m, ifp, 3));
1018 else
1019 IFQ_HANDOFF_ADJ(ifp, m, 3, error);
1020 if (error) {
1021 ++ifp->if_oerrors;
1022 SPPP_UNLOCK(sp);
1023 splx (s);

--- 146 unchanged lines hidden (view full) ---

1170 /*
1171 * Process only the control protocol queue until we have at
1172 * least one NCP open.
1173 *
1174 * Do always serve all three queues in Cisco mode.
1175 */
1176 IF_DEQUEUE(&sp->pp_cpq, m);
1177 if (m == NULL &&
1165 (sppp_ncp_check(sp) || sp->pp_mode == IFF_CISCO)) {
1178 (sppp_ncp_check(sp) || sp->pp_mode == IFF_CISCO ||
1179 sp->pp_mode == PP_FR)) {
1180 IF_DEQUEUE(&sp->pp_fastq, m);
1181 if (m == NULL)
1182 IF_DEQUEUE (&sp->pp_if.if_snd, m);
1183 }
1184 SPPP_UNLOCK(sp);
1185 splx(s);
1186 return m;
1187}

--- 9 unchanged lines hidden (view full) ---

1197 int s;
1198
1199 s = splimp ();
1200 SPPP_LOCK(sp);
1201
1202 m = sp->pp_cpq.ifq_head;
1203 if (m == NULL &&
1204 (sp->pp_phase == PHASE_NETWORK ||
1191 sp->pp_mode == IFF_CISCO))
1205 sp->pp_mode == IFF_CISCO ||
1206 sp->pp_mode == PP_FR))
1207 if ((m = sp->pp_fastq.ifq_head) == NULL)
1208 m = sp->pp_if.if_snd.ifq_head;
1209 SPPP_UNLOCK(sp);
1210 splx (s);
1211 return (m);
1212}
1213
1214/*

--- 28 unchanged lines hidden (view full) ---

1243 newmode = ifp->if_flags & IFF_PASSIVE;
1244 if (!newmode)
1245 newmode = ifp->if_flags & IFF_AUTO;
1246 if (!newmode)
1247 newmode = ifp->if_flags & IFF_CISCO;
1248 ifp->if_flags &= ~(IFF_PASSIVE | IFF_AUTO | IFF_CISCO);
1249 ifp->if_flags |= newmode;
1250
1251 if (!newmode)
1252 newmode = sp->pp_flags & PP_FR;
1253
1254 if (newmode != sp->pp_mode) {
1255 going_down = 1;
1256 if (!going_up)
1257 going_up = ifp->if_flags & IFF_RUNNING;
1258 }
1259
1260 if (going_down) {
1243 if (sp->pp_mode != IFF_CISCO)
1261 if (sp->pp_mode != IFF_CISCO &&
1262 sp->pp_mode != PP_FR)
1263 lcp.Close(sp);
1264 else if (sp->pp_tlf)
1265 (sp->pp_tlf)(sp);
1266 sppp_flush_unlocked(ifp);
1267 ifp->if_flags &= ~IFF_RUNNING;
1268 sp->pp_mode = newmode;
1269 }
1270
1271 if (going_up) {
1253 if (sp->pp_mode != IFF_CISCO)
1272 if (sp->pp_mode != IFF_CISCO &&
1273 sp->pp_mode != PP_FR)
1274 lcp.Close(sp);
1275 sp->pp_mode = newmode;
1276 if (sp->pp_mode == 0) {
1277 ifp->if_flags |= IFF_RUNNING;
1278 lcp.Open(sp);
1279 }
1260 if (sp->pp_mode == IFF_CISCO) {
1280 if ((sp->pp_mode == IFF_CISCO) ||
1281 (sp->pp_mode == PP_FR)) {
1282 if (sp->pp_tls)
1283 (sp->pp_tls)(sp);
1284 ifp->if_flags |= IFF_RUNNING;
1285 }
1286 }
1287
1288 break;
1289

--- 3495 unchanged lines hidden (view full) ---

4785
4786 s = splimp();
4787 SPPP_LOCK(sp);
4788 /* Keepalive mode disabled or channel down? */
4789 if (! (sp->pp_flags & PP_KEEPALIVE) ||
4790 ! (ifp->if_flags & IFF_RUNNING))
4791 goto out;
4792
4793 if (sp->pp_mode == PP_FR) {
4794 sppp_fr_keepalive (sp);
4795 goto out;
4796 }
4797
4798 /* No keepalive in PPP mode if LCP not opened yet. */
4799 if (sp->pp_mode != IFF_CISCO &&
4800 sp->pp_phase < PHASE_AUTHENTICATE)
4801 goto out;
4802
4803 if (sp->pp_alivecnt == MAXALIVECNT) {
4804 /* No keepalive packets got. Stop the interface. */
4805 printf (SPP_FMT "down\n", SPP_ARGS(ifp));

--- 23 unchanged lines hidden (view full) ---

4829 splx(s);
4830 callout_reset(&sp->keepalive_callout, hz * 10, sppp_keepalive,
4831 (void *)sp);
4832}
4833
4834/*
4835 * Get both IP addresses.
4836 */
4811static void
4837void
4838sppp_get_ip_addrs(struct sppp *sp, u_long *src, u_long *dst, u_long *srcmask)
4839{
4840 struct ifnet *ifp = &sp->pp_if;
4841 struct ifaddr *ifa;
4842 struct sockaddr_in *si, *sm;
4843 u_long ssrc, ddst;
4844
4845 sm = NULL;

--- 629 unchanged lines hidden ---