1224006Shrs/*-
2224006Shrs * Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org>
3224006Shrs * All rights reserved.
4224006Shrs *
5224006Shrs * Redistribution and use in source and binary forms, with or without
6224006Shrs * modification, are permitted provided that the following conditions
7224006Shrs * are met:
8224006Shrs * 1. Redistributions of source code must retain the above copyright
9224006Shrs *    notice, this list of conditions and the following disclaimer.
10224006Shrs * 2. Redistributions in binary form must reproduce the above copyright
11224006Shrs *    notice, this list of conditions and the following disclaimer in the
12224006Shrs *    documentation and/or other materials provided with the distribution.
13224006Shrs *
14224006Shrs * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
15224006Shrs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16224006Shrs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17224006Shrs * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
18224006Shrs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19224006Shrs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20224006Shrs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21224006Shrs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22224006Shrs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23224006Shrs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24224006Shrs * SUCH DAMAGE.
25224006Shrs *
26224006Shrs * $FreeBSD$
27224006Shrs *
28224006Shrs */
29224006Shrs
30224006Shrs#define	SOCK_BACKLOG		5
31224006Shrs
32224006Shrs#define	CM_MSG_MAXLEN		8192
33224006Shrs#define	CM_VERSION		1
34224006Shrs#define	CM_VERSION_STR		"1.0"
35224006Shrs
36224006Shrs#define	CM_TYPE_EOM		0
37224006Shrs#define	CM_TYPE_ACK		1
38224006Shrs#define	CM_TYPE_ERR		2
39224006Shrs#define	CM_TYPE_NUL		3
40224006Shrs#define	CM_TYPE_REQ_SET_PROP	4
41224006Shrs#define	CM_TYPE_REQ_GET_PROP	5
42224006Shrs#define	CM_TYPE_MAX		6
43224006Shrs
44224006Shrs#define	CM_STATE_EOM		0
45224006Shrs#define	CM_STATE_INIT		1
46224006Shrs#define	CM_STATE_MSG_DISPATCH	2
47224006Shrs#define	CM_STATE_MSG_RECV	3
48224006Shrs#define	CM_STATE_ACK_WAIT	4
49224006Shrs
50224006Shrsstruct ctrl_msg_hdr {
51224006Shrs	int	cm_version;
52224006Shrs	size_t	cm_len;
53224006Shrs	int	cm_type;
54224006Shrs};
55224006Shrs
56224006Shrsstruct ctrl_msg_pl {
57224006Shrs	char	*cp_ifname;
58224006Shrs	char	*cp_key;
59224006Shrs
60224006Shrs	size_t	cp_val_len;
61224006Shrs	char	*cp_val;
62224006Shrs};
63224006Shrs
64224006Shrsint	csock_open(struct sockinfo *, mode_t);
65224006Shrsint	csock_close(struct sockinfo *);
66224006Shrsint	csock_listen(struct sockinfo *);
67224006Shrsint	csock_accept(struct sockinfo *);
68225519Shrsint	cm_send(int, char *);
69225519Shrsint	cm_recv(int, char *);
70224006Shrs
71225519Shrssize_t			cm_pl2bin(char *, struct ctrl_msg_pl *);
72225519Shrsstruct ctrl_msg_pl	*cm_bin2pl(char *, struct ctrl_msg_pl *);
73225519Shrssize_t			cm_str2bin(char *, void *, size_t);
74225519Shrsvoid			*cm_bin2str(char *, void *, size_t);
75