Project

General

Profile

Bug #7145 » patch-dhcp6c.c

Martin Wasley, 01/30/2017 11:13 AM

 
1
--- dhcp6c.c.orig	2016-12-19 08:16:42 UTC
2
+++ dhcp6c.c
3
@@ -82,9 +82,12 @@
4
 
5
 static int debug = 0;
6
 static int exit_ok = 0;
7
+
8
 static sig_atomic_t sig_flags = 0;
9
 #define SIGF_TERM 0x1
10
 #define SIGF_HUP 0x2
11
+#define SIGF_QUIT 0x4
12
+
13
 
14
 const dhcp6_mode_t dhcp6_mode = DHCP6_MODE_CLIENT;
15
 
16
@@ -109,6 +112,7 @@ static int ctldigestlen;
17
 static int infreq_mode = 0;
18
 
19
 int opt_norelease;
20
+static char *script_p;
21
 
22
 static inline int get_val32 __P((char **, int *, u_int32_t *));
23
 static inline int get_ifname __P((char **, int *, char *, int));
24
@@ -390,6 +394,11 @@ client6_init()
25
 		    strerror(errno));
26
 		exit(1);
27
 	}
28
+	if (signal(SIGUSR1, client6_signal) == SIG_ERR) {
29
+		d_printf(LOG_WARNING, FNAME, "failed to set signal: %s",
30
+		    strerror(errno));
31
+		exit(1);
32
+	}
33
 }
34
 
35
 int
36
@@ -454,6 +463,9 @@ free_resources(freeifp)
37
 {
38
 	struct dhcp6_if *ifp;
39
 
40
+	
41
+	script_p = NULL;
42
+	
43
 	for (ifp = dhcp6_if; ifp; ifp = ifp->next) {
44
 		struct dhcp6_event *ev, *ev_next;
45
 
46
@@ -461,6 +473,11 @@ free_resources(freeifp)
47
 			continue;
48
 
49
 		/* release all IAs as well as send RELEASE message(s) */
50
+		if(script_p == NULL) {
51
+		    script_p = ifp->scriptpath;
52
+		    
53
+		}
54
+		
55
 		release_all_ia(ifp);
56
 
57
 		/*
58
@@ -483,20 +500,32 @@ check_exit()
59
 {
60
 	struct dhcp6_if *ifp;
61
 
62
+	
63
+	
64
 	if (!exit_ok)
65
 		return;
66
 
67
-	for (ifp = dhcp6_if; ifp; ifp = ifp->next) {
68
-		/*
69
-		 * Check if we have an outstanding event.  If we do, we cannot
70
-		 * exit for now.
71
-		 */
72
-		if (!TAILQ_EMPTY(&ifp->event_list))
73
+	if(exit_ok) {
74
+	  
75
+		for (ifp = dhcp6_if; ifp; ifp = ifp->next) {
76
+			/*
77
+			* Check if we have an outstanding event.  If we do, we cannot
78
+			* exit for now.
79
+			*/
80
+			
81
+			if (!TAILQ_EMPTY(&ifp->event_list))
82
 			return;
83
+		}
84
 	}
85
-
86
+	
87
 	/* We have no existing event.  Do exit. */
88
 	d_printf(LOG_INFO, FNAME, "exiting");
89
+	
90
+	if (strlen(script_p) != 0) {
91
+		    /* We are going to fire the script with and exit value */
92
+		     d_printf(LOG_DEBUG, FNAME, "shutdown executes %s", script_p);
93
+		     client6_script(script_p, DHCP6S_EXIT, NULL);
94
+	} 
95
 
96
 	exit(0);
97
 }
98
@@ -504,6 +533,8 @@ check_exit()
99
 static void
100
 process_signals()
101
 {
102
+     
103
+	 
104
 	if ((sig_flags & SIGF_TERM)) {
105
 		exit_ok = 1;
106
 		free_resources(NULL);
107
@@ -515,6 +546,14 @@ process_signals()
108
 		free_resources(NULL);
109
 		client6_startall(1);
110
 	}
111
+	if ((sig_flags & SIGF_QUIT)) {
112
+		d_printf(LOG_INFO, FNAME, "Forcing Exit");
113
+		exit_ok = 1;
114
+		opt_norelease = 1;
115
+		free_resources(NULL);
116
+		unlink(pid_file);
117
+		check_exit();
118
+	}
119
 
120
 	sig_flags = 0;
121
 }
122
@@ -1161,6 +1200,9 @@ client6_signal(sig)
123
 	case SIGHUP:
124
 		sig_flags |= SIGF_HUP;
125
 		break;
126
+	case SIGUSR1:
127
+		sig_flags |= SIGF_QUIT;
128
+		break;
129
 	}
130
 }
131
 
132
@@ -1751,23 +1793,23 @@ client6_recvreply(ifp, dh6, len, optinfo
133
 
134
 	switch (state) {
135
 	case DHCP6S_INFOREQ:
136
-		d_printf(LOG_INFO, FNAME, "dhcp6c Received INFOREQ");
137
-		break;  
138
-	case DHCP6S_REQUEST:
139
-		d_printf(LOG_INFO, FNAME, "dhcp6c Received REQUEST");
140
-		break;
141
-	case DHCP6S_RENEW:
142
-		d_printf(LOG_INFO, FNAME, "dhcp6c Received INFO");
143
-		break;
144
-	case DHCP6S_REBIND:
145
-		d_printf(LOG_INFO, FNAME, "dhcp6c Received REBIND");
146
-		break;
147
-	case DHCP6S_RELEASE:
148
-		d_printf(LOG_INFO, FNAME, "dhcp6c Received RELEASE");
149
-		break;
150
-	case DHCP6S_SOLICIT:
151
-		d_printf(LOG_INFO, FNAME, "dhcp6c Received SOLICIT");
152
-		break;          
153
+		d_printf(LOG_INFO, FNAME, "Received Info");
154
+ 		break;  
155
+ 	case DHCP6S_REQUEST:
156
+		d_printf(LOG_INFO, FNAME, "Received Reply");
157
+ 		break;
158
+ 	case DHCP6S_RENEW:
159
+		d_printf(LOG_INFO, FNAME, "Received Renew");
160
+ 		break;
161
+ 	case DHCP6S_REBIND:
162
+		d_printf(LOG_INFO, FNAME, "Received Rebind");
163
+ 		break;
164
+ 	case DHCP6S_RELEASE:
165
+		d_printf(LOG_INFO, FNAME, "Received Release");
166
+ 		break;
167
+ 	case DHCP6S_SOLICIT:
168
+		d_printf(LOG_INFO, FNAME, "Received Advert");
169
+ 		break;             
170
 	}
171
 
172
 	/* A Reply message must contain a Server ID option */
(10-10/11)