From adab5daca34dea394625349afd6090e6b69f4558 Mon Sep 17 00:00:00 2001
From: Maxime Bizon <mbizon@freebox.fr>
Date: Thu, 16 Jan 2020 00:59:55 +0100
Subject: [PATCH 04/18] pppd: add notifier on first LCP packet

---
 pppd/lcp.c  | 8 ++++++++
 pppd/pppd.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/pppd/lcp.c b/pppd/lcp.c
index 625d2f7..e09ae05 100644
--- a/pppd/lcp.c
+++ b/pppd/lcp.c
@@ -195,9 +195,12 @@ lcp_options lcp_hisoptions[NUM_PPP];	/* Options that we ack'd */
 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 */
+static int lcp_first_pkt = 0;		/* set if we received first pkt */
 
 static u_char nak_buffer[PPP_MRU];	/* where we construct a nak packet */
 
+struct notifier *first_lcp_notifier = NULL;
+
 /*
  * Callbacks for fsm code.  (CI = Configuration Information)
  */
@@ -339,6 +342,7 @@ lcp_init(unit)
     lcp_options *wo = &lcp_wantoptions[unit];
     lcp_options *ao = &lcp_allowoptions[unit];
 
+    lcp_first_pkt = 0;
     f->unit = unit;
     f->protocol = PPP_LCP;
     f->callbacks = &lcp_callbacks;
@@ -495,6 +499,10 @@ lcp_input(unit, p, len)
 {
     fsm *f = &lcp_fsm[unit];
 
+    if (!lcp_first_pkt) {
+	lcp_first_pkt = 1;
+	notify(first_lcp_notifier, 0);
+    }
     if (f->flags & DELAYED_UP) {
 	f->flags &= ~DELAYED_UP;
 	untimeout(lcp_delayed_up, f);
diff --git a/pppd/pppd.h b/pppd/pppd.h
index b31b78d..122a042 100644
--- a/pppd/pppd.h
+++ b/pppd/pppd.h
@@ -277,6 +277,7 @@ extern struct notifier *ipv6_down_notifier; /* IPV6CP has gone down */
 extern struct notifier *auth_up_notifier; /* peer has authenticated */
 extern struct notifier *link_down_notifier; /* link has gone down */
 extern struct notifier *fork_notifier;	/* we are a new child process */
+extern struct notifier *first_lcp_notifier; /* first LCP packet received */
 
 /* Values for do_callback and doing_callback */
 #define CALLBACK_DIALIN		1	/* we are expecting the call back */
-- 
2.17.1

