GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: sbin/dhclient/privsep.c Lines: 0 30 0.0 %
Date: 2016-12-06 Branches: 0 25 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: privsep.c,v 1.40 2016/02/06 19:30:52 krw Exp $ */
2
3
/*
4
 * Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
5
 *
6
 * Permission to use, copy, modify, and distribute this software for any
7
 * purpose with or without fee is hereby granted, provided that the above
8
 * copyright notice and this permission notice appear in all copies.
9
 *
10
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
15
 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
16
 * OF OR IN CONNECTION WITH THE USE, ABUSE OR PERFORMANCE OF THIS SOFTWARE.
17
 */
18
19
#include <sys/queue.h>
20
#include <sys/socket.h>
21
22
#include <net/if.h>
23
24
#include <netinet/in.h>
25
#include <netinet/if_ether.h>
26
27
#include <errno.h>
28
#include <imsg.h>
29
#include <signal.h>
30
#include <stdio.h>
31
#include <string.h>
32
33
#include "dhcp.h"
34
#include "dhcpd.h"
35
#include "privsep.h"
36
37
void
38
dispatch_imsg(struct imsgbuf *ibuf)
39
{
40
	struct imsg			 imsg;
41
	ssize_t				 n;
42
43
	for (;;) {
44
		if ((n = imsg_get(ibuf, &imsg)) == -1)
45
			error("dispatch_imsg: imsg_get failure: %s",
46
			    strerror(errno));
47
48
		if (n == 0)
49
			break;
50
51
		switch (imsg.hdr.type) {
52
		case IMSG_DELETE_ADDRESS:
53
			if (imsg.hdr.len != IMSG_HEADER_SIZE +
54
			    sizeof(struct imsg_delete_address))
55
				warning("bad IMSG_DELETE_ADDRESS");
56
			else
57
				priv_delete_address(imsg.data);
58
			break;
59
60
		case IMSG_ADD_ADDRESS:
61
			if (imsg.hdr.len != IMSG_HEADER_SIZE +
62
			    sizeof(struct imsg_add_address))
63
				warning("bad IMSG_ADD_ADDRESS");
64
			else
65
				priv_add_address(imsg.data);
66
			break;
67
68
		case IMSG_FLUSH_ROUTES:
69
			if (imsg.hdr.len != IMSG_HEADER_SIZE +
70
			    sizeof(struct imsg_flush_routes))
71
				warning("bad IMSG_FLUSH_ROUTES");
72
			else
73
				priv_flush_routes(imsg.data);
74
			break;
75
76
		case IMSG_ADD_ROUTE:
77
			if (imsg.hdr.len != IMSG_HEADER_SIZE +
78
			    sizeof(struct imsg_add_route))
79
				warning("bad IMSG_ADD_ROUTE");
80
			else
81
				priv_add_route(imsg.data);
82
			break;
83
84
		case IMSG_SET_INTERFACE_MTU:
85
			if (imsg.hdr.len != IMSG_HEADER_SIZE +
86
			    sizeof(struct imsg_set_interface_mtu))
87
				warning("bad IMSG_SET_INTERFACE_MTU");
88
			else
89
				priv_set_interface_mtu(imsg.data);
90
			break;
91
92
		case IMSG_HUP:
93
			if (imsg.hdr.len != IMSG_HEADER_SIZE +
94
			    sizeof(struct imsg_hup))
95
				warning("bad IMSG_HUP");
96
			else {
97
				ifi->flags |= IFI_HUP;
98
				quit = SIGHUP;
99
			}
100
			break;
101
102
		case IMSG_WRITE_RESOLV_CONF:
103
			priv_write_resolv_conf(&imsg);
104
			break;
105
		case IMSG_WRITE_OPTION_DB:
106
			priv_write_option_db(&imsg);
107
			break;
108
109
		default:
110
			warning("received unknown message, code %u",
111
			    imsg.hdr.type);
112
		}
113
114
		imsg_free(&imsg);
115
	}
116
}