xref: /freebsd/usr.sbin/rtadvd/control.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
137241896SHiroki Sato /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
31de7b4b8SPedro F. Giffuni  *
437241896SHiroki Sato  * Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org>
537241896SHiroki Sato  * All rights reserved.
637241896SHiroki Sato  *
737241896SHiroki Sato  * Redistribution and use in source and binary forms, with or without
837241896SHiroki Sato  * modification, are permitted provided that the following conditions
937241896SHiroki Sato  * are met:
1037241896SHiroki Sato  * 1. Redistributions of source code must retain the above copyright
1137241896SHiroki Sato  *    notice, this list of conditions and the following disclaimer.
1237241896SHiroki Sato  * 2. Redistributions in binary form must reproduce the above copyright
1337241896SHiroki Sato  *    notice, this list of conditions and the following disclaimer in the
1437241896SHiroki Sato  *    documentation and/or other materials provided with the distribution.
1537241896SHiroki Sato  *
1637241896SHiroki Sato  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
1737241896SHiroki Sato  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1837241896SHiroki Sato  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1937241896SHiroki Sato  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2037241896SHiroki Sato  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2137241896SHiroki Sato  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2237241896SHiroki Sato  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2337241896SHiroki Sato  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2437241896SHiroki Sato  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2537241896SHiroki Sato  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2637241896SHiroki Sato  * SUCH DAMAGE.
2737241896SHiroki Sato  *
2837241896SHiroki Sato  */
2937241896SHiroki Sato 
3037241896SHiroki Sato #define	SOCK_BACKLOG		5
3137241896SHiroki Sato 
3237241896SHiroki Sato #define	CM_MSG_MAXLEN		8192
3337241896SHiroki Sato #define	CM_VERSION		1
3437241896SHiroki Sato #define	CM_VERSION_STR		"1.0"
3537241896SHiroki Sato 
3637241896SHiroki Sato #define	CM_TYPE_EOM		0
3737241896SHiroki Sato #define	CM_TYPE_ACK		1
3837241896SHiroki Sato #define	CM_TYPE_ERR		2
3937241896SHiroki Sato #define	CM_TYPE_NUL		3
4037241896SHiroki Sato #define	CM_TYPE_REQ_SET_PROP	4
4137241896SHiroki Sato #define	CM_TYPE_REQ_GET_PROP	5
4237241896SHiroki Sato #define	CM_TYPE_MAX		6
4337241896SHiroki Sato 
4437241896SHiroki Sato #define	CM_STATE_EOM		0
4537241896SHiroki Sato #define	CM_STATE_INIT		1
4637241896SHiroki Sato #define	CM_STATE_MSG_DISPATCH	2
4737241896SHiroki Sato #define	CM_STATE_MSG_RECV	3
4837241896SHiroki Sato #define	CM_STATE_ACK_WAIT	4
4937241896SHiroki Sato 
5037241896SHiroki Sato struct ctrl_msg_hdr {
5137241896SHiroki Sato 	int	cm_version;
5237241896SHiroki Sato 	size_t	cm_len;
5337241896SHiroki Sato 	int	cm_type;
5437241896SHiroki Sato };
5537241896SHiroki Sato 
5637241896SHiroki Sato struct ctrl_msg_pl {
5737241896SHiroki Sato 	char	*cp_ifname;
5837241896SHiroki Sato 	char	*cp_key;
5937241896SHiroki Sato 
6037241896SHiroki Sato 	size_t	cp_val_len;
6137241896SHiroki Sato 	char	*cp_val;
6237241896SHiroki Sato };
6337241896SHiroki Sato 
6437241896SHiroki Sato int	csock_open(struct sockinfo *, mode_t);
6537241896SHiroki Sato int	csock_close(struct sockinfo *);
6637241896SHiroki Sato int	csock_listen(struct sockinfo *);
6737241896SHiroki Sato int	csock_accept(struct sockinfo *);
68aed37872SHiroki Sato int	cm_send(int, char *);
69aed37872SHiroki Sato int	cm_recv(int, char *);
7037241896SHiroki Sato 
71aed37872SHiroki Sato size_t			cm_pl2bin(char *, struct ctrl_msg_pl *);
72aed37872SHiroki Sato struct ctrl_msg_pl	*cm_bin2pl(char *, struct ctrl_msg_pl *);
73aed37872SHiroki Sato size_t			cm_str2bin(char *, void *, size_t);
74aed37872SHiroki Sato void			*cm_bin2str(char *, void *, size_t);
75