From 7e18aec492a472e63759b05f48117e677096456a Mon Sep 17 00:00:00 2001
From: Maxime Bizon <mbizon@freebox.fr>
Date: Thu, 16 Jan 2020 01:05:15 +0100
Subject: [PATCH 04/12] pppd: add mppe state change notifier

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

diff --git a/pppd/ccp.c b/pppd/ccp.c
index 732091f..a30af4e 100644
--- a/pppd/ccp.c
+++ b/pppd/ccp.c
@@ -162,6 +162,8 @@ static struct option ccp_option_list[] = {
     { NULL }
 };
 
+struct notifier *mppe_state_notifier = NULL;
+
 /*
  * Protocol entry points from main code.
  */
@@ -1428,6 +1430,11 @@ ccp_up(fsm *f)
 	notice("%s transmit compression enabled", method_name(ho, NULL));
 #ifdef PPP_WITH_MPPE
     if (go->mppe) {
+	int arg = (1 << 0);
+
+	if ((go->mppe & MPPE_OPT_128))
+		arg |= (1 << 1);
+	notify(mppe_state_notifier, arg);
 	mppe_clear_keys();
 	continue_networks(f->unit);		/* Bring up IP et al */
     }
@@ -1449,6 +1456,7 @@ ccp_down(fsm *f)
 	ccp_gotoptions[f->unit].mppe = 0;
 	if (lcp_fsm[f->unit].state == OPENED) {
 	    /* If LCP is not already going down, make sure it does. */
+	    notify(mppe_state_notifier, 0);
 	    error("MPPE disabled");
 	    lcp_close(f->unit, "MPPE disabled");
 	}
diff --git a/pppd/main.c b/pppd/main.c
index e3e7b87..ea0b733 100644
--- a/pppd/main.c
+++ b/pppd/main.c
@@ -2099,6 +2099,7 @@ struct notifier **get_notifier_by_type(ppp_notify_t type)
         [NF_FORK        ] = &fork_notifier,
         [NF_FIRST_LCP   ] = &first_lcp_notifier,
         [NF_AUTH_WITH_PEER] = &auth_with_peer_notifier,
+        [NF_MPPE_STATE  ] = &mppe_state_notifier,
     };
     return list[type];
 }
diff --git a/pppd/pppd-private.h b/pppd/pppd-private.h
index 796a0a3..b0aa798 100644
--- a/pppd/pppd-private.h
+++ b/pppd/pppd-private.h
@@ -140,6 +140,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 *auth_with_peer_notifier; /* we have authenticated  */
+extern struct notifier *mppe_state_notifier; /* mppe state changed */
 
 
 /* Values for do_callback and doing_callback */
diff --git a/pppd/pppd.h b/pppd/pppd.h
index 62bb14a..217cdc1 100644
--- a/pppd/pppd.h
+++ b/pppd/pppd.h
@@ -149,6 +149,7 @@ typedef enum
     NF_FORK,
     NF_FIRST_LCP,
     NF_AUTH_WITH_PEER,
+    NF_MPPE_STATE,
     NF_MAX_NOTIFY
 } ppp_notify_t;
 
-- 
2.34.1

