1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
$NetBSD: patch-ar,v 1.1.1.1 2005/01/02 02:51:42 cube Exp $
--- pppd/lcp.c.orig 2004-11-13 03:28:15.000000000 +0100
+++ pppd/lcp.c
@@ -193,6 +193,18 @@ lcp_options lcp_gotoptions[NUM_PPP]; /*
lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
+/* Hook for LCP up */
+void (*lcp_up_hook) __P((void)) = NULL;
+
+/* Hook for LCP down */
+void (*lcp_down_hook) __P((void)) = NULL;
+
+/* Hook for sending an LCP echo request, argument is pending count */
+void (*lcp_echo_hook) __P((int)) = NULL;
+
+/* Hook for receiving an LCP echo reply, argument is whether it's ours */
+void (*lcp_echoreply_hook) __P((int)) = NULL;
+
static int lcp_echos_pending = 0; /* Number of outstanding echo msgs */
static int lcp_echo_number = 0; /* ID number of next echo frame */
static int lcp_echo_timer_running = 0; /* set if a timer is running */
@@ -1907,6 +1919,8 @@ lcp_up(f)
if (ho->neg_mru)
peer_mru[f->unit] = ho->mru;
+ if (lcp_up_hook) (*lcp_up_hook)();
+
lcp_echo_lowerup(f->unit); /* Enable echo messages */
link_established(f->unit);
@@ -1928,6 +1942,8 @@ lcp_down(f)
link_down(f->unit);
+ if (lcp_down_hook) (*lcp_down_hook)();
+
ppp_send_config(f->unit, PPP_MRU, 0xffffffff, 0, 0);
ppp_recv_config(f->unit, PPP_MRU,
(go->neg_asyncmap? go->asyncmap: 0xffffffff),
@@ -2260,8 +2276,10 @@ lcp_received_echo_reply (f, id, inp, len
if (lcp_gotoptions[f->unit].neg_magicnumber
&& magic == lcp_gotoptions[f->unit].magicnumber) {
warn("appear to have received our own echo-reply!");
+ if (lcp_echoreply_hook) (*lcp_echoreply_hook)(1);
return;
}
+ if (lcp_echoreply_hook) (*lcp_echoreply_hook)(0);
/* Reset the number of outstanding echo frames */
lcp_echos_pending = 0;
@@ -2278,6 +2296,9 @@ LcpSendEchoRequest (f)
u_int32_t lcp_magic;
u_char pkt[4], *pktp;
+ if (f->state != OPENED)
+ return;
+
/*
* Detect the failure of the peer at this point.
*/
@@ -2291,13 +2312,12 @@ LcpSendEchoRequest (f)
/*
* Make and send the echo request frame.
*/
- if (f->state == OPENED) {
- lcp_magic = lcp_gotoptions[f->unit].magicnumber;
- pktp = pkt;
- PUTLONG(lcp_magic, pktp);
- fsm_sdata(f, ECHOREQ, lcp_echo_number++ & 0xFF, pkt, pktp - pkt);
- ++lcp_echos_pending;
- }
+ if (lcp_echo_hook) (*lcp_echo_hook)(lcp_echos_pending);
+ lcp_magic = lcp_gotoptions[f->unit].magicnumber;
+ pktp = pkt;
+ PUTLONG(lcp_magic, pktp);
+ fsm_sdata(f, ECHOREQ, lcp_echo_number++ & 0xFF, pkt, pktp - pkt);
+ ++lcp_echos_pending;
}
/*
|