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

---
 pppd/lcp.c          | 8 ++++++++
 pppd/main.c         | 1 +
 pppd/pppd-private.h | 1 +
 pppd/pppd.h         | 1 +
 4 files changed, 11 insertions(+)

diff --git a/pppd/lcp.c b/pppd/lcp.c
index 0876b8a..624d200 100644
--- a/pppd/lcp.c
+++ b/pppd/lcp.c
@@ -217,9 +217,12 @@ 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_rtt_file_fd = 0;		/* fd for the opened LCP RTT file */
 static u_int32_t *lcp_rtt_buffer = NULL; /* the mmap'ed LCP RTT file */
+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)
  */
@@ -354,6 +357,7 @@ lcp_init(int 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;
@@ -501,6 +505,10 @@ lcp_input(int unit, u_char *p, int 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/main.c b/pppd/main.c
index 3b3fc45..8aec5cb 100644
--- a/pppd/main.c
+++ b/pppd/main.c
@@ -2097,6 +2097,7 @@ struct notifier **get_notifier_by_type(ppp_notify_t type)
         [NF_AUTH_UP     ] = &auth_up_notifier,
         [NF_LINK_DOWN   ] = &link_down_notifier,
         [NF_FORK        ] = &fork_notifier,
+        [NF_FIRST_LCP   ] = &first_lcp_notifier,
     };
     return list[type];
 }
diff --git a/pppd/pppd-private.h b/pppd/pppd-private.h
index d8ec443..66dd15e 100644
--- a/pppd/pppd-private.h
+++ b/pppd/pppd-private.h
@@ -138,6 +138,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 */
diff --git a/pppd/pppd.h b/pppd/pppd.h
index 4f02021..bd9736d 100644
--- a/pppd/pppd.h
+++ b/pppd/pppd.h
@@ -130,6 +130,7 @@ typedef enum
     NF_AUTH_UP,
     NF_LINK_DOWN,
     NF_FORK,
+    NF_FIRST_LCP,
     NF_MAX_NOTIFY
 } ppp_notify_t;
 
-- 
2.34.1

