From 523dd131ec4e2d8bf21743fc94d635cb6613024b Mon Sep 17 00:00:00 2001
From: Maxime Bizon <mbizon@freebox.fr>
Date: Tue, 28 Jan 2020 18:23:14 +0100
Subject: [PATCH 18/18] pppd: add new network up notifier

only trigger when all opened network protocols are up

this allows waiting for ip and ipv6 to be done
---
 pppd/auth.c | 14 ++++++++++++++
 pppd/pppd.h |  1 +
 2 files changed, 15 insertions(+)

diff --git a/pppd/auth.c b/pppd/auth.c
index 20808b1..9d517a4 100644
--- a/pppd/auth.c
+++ b/pppd/auth.c
@@ -208,6 +208,10 @@ struct notifier *auth_with_peer_notifier = NULL;
 /* A notifier for when the link goes down. */
 struct notifier *link_down_notifier = NULL;
 
+/* A notifier when all possible network protocols are up. */
+struct notifier *network_up_notifier = NULL;
+static int network_up = 0;
+
 /*
  * This is used to ensure that we don't start an auth-up/down
  * script while one is already running.
@@ -726,6 +730,7 @@ void upper_layers_down(int unit)
     }
     num_np_open = 0;
     num_np_up = 0;
+    network_up = 0;
 }
 
 /*
@@ -1122,6 +1127,11 @@ np_up(unit, proto)
 	}
     }
     ++num_np_up;
+
+    if (num_np_up == num_np_open && !network_up) {
+	    network_up = 1;
+	    notify(network_up_notifier, 0);
+    }
 }
 
 /*
@@ -1152,6 +1162,10 @@ np_finished(unit, proto)
 	/* no further use for the link: shut up shop. */
 	lcp_close(0, "No network protocols running");
     }
+    if (num_np_up && num_np_up == num_np_open && !network_up) {
+	    network_up = 1;
+	    notify(network_up_notifier, 0);
+    }
 }
 
 #ifdef MAXOCTETS
diff --git a/pppd/pppd.h b/pppd/pppd.h
index e15032c..201b7ce 100644
--- a/pppd/pppd.h
+++ b/pppd/pppd.h
@@ -280,6 +280,7 @@ 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 */
 extern struct notifier *mppe_state_notifier; /* mppe state changed */
+extern struct notifier *network_up_notifier; /* all network protocols are up */
 
 /* Values for do_callback and doing_callback */
 #define CALLBACK_DIALIN		1	/* we are expecting the call back */
-- 
2.17.1

