2 * Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
21 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: stable/10/usr.sbin/rtadvd/control_client.c 225519 2011-09-12 23:52:55Z hrs $
30 #include <sys/queue.h>
31 #include <sys/types.h>
32 #include <sys/socket.h>
37 #include <net/if_dl.h>
38 #include <netinet/in.h>
39 #include <netinet/icmp6.h>
51 #include "pathnames.h"
55 #include "control_client.h"
58 cm_handler_client(int fd, int state, char *buf_orig)
60 char buf[CM_MSG_MAXLEN];
61 struct ctrl_msg_hdr *cm;
62 struct ctrl_msg_hdr *cm_orig;
67 syslog(LOG_DEBUG, "<%s> enter", __func__);
69 memset(buf, 0, sizeof(buf));
70 cm = (struct ctrl_msg_hdr *)buf;
71 cm_orig = (struct ctrl_msg_hdr *)buf_orig;
72 msg = (char *)buf + sizeof(*cm);
73 msg_orig = (char *)buf_orig + sizeof(*cm_orig);
75 if (cm_orig->cm_len > CM_MSG_MAXLEN) {
76 syslog(LOG_DEBUG, "<%s> msg too long", __func__);
80 cm->cm_type = cm_orig->cm_type;
81 if (cm_orig->cm_len > sizeof(*cm_orig)) {
82 memcpy(msg, msg_orig, cm_orig->cm_len - sizeof(*cm));
83 cm->cm_len = cm_orig->cm_len;
85 while (state != CM_STATE_EOM) {
86 syslog(LOG_DEBUG, "<%s> state = %d", __func__, state);
92 case CM_STATE_MSG_DISPATCH:
93 cm->cm_version = CM_VERSION;
94 error = cm_send(fd, buf);
97 "<%s> cm_send()", __func__);
98 state = CM_STATE_ACK_WAIT;
100 case CM_STATE_ACK_WAIT:
101 error = cm_recv(fd, buf);
104 "<%s> cm_recv()", __func__);
108 switch (cm->cm_type) {
111 "<%s> CM_TYPE_ACK", __func__);
115 "<%s> CM_TYPE_ERR", __func__);
120 "<%s> unknown status", __func__);
124 memcpy(buf_orig, buf, cm->cm_len);
125 state = CM_STATE_EOM;