xref: /freebsd/usr.sbin/ppp/ncpaddr.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
130949fd4SBrian Somers /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
31de7b4b8SPedro F. Giffuni  *
430949fd4SBrian Somers  * Copyright (c) 2001 Brian Somers <brian@Awfulhak.org>
530949fd4SBrian Somers  * All rights reserved.
630949fd4SBrian Somers  *
730949fd4SBrian Somers  * Redistribution and use in source and binary forms, with or without
830949fd4SBrian Somers  * modification, are permitted provided that the following conditions
930949fd4SBrian Somers  * are met:
1030949fd4SBrian Somers  * 1. Redistributions of source code must retain the above copyright
1130949fd4SBrian Somers  *    notice, this list of conditions and the following disclaimer.
1230949fd4SBrian Somers  * 2. Redistributions in binary form must reproduce the above copyright
1330949fd4SBrian Somers  *    notice, this list of conditions and the following disclaimer in the
1430949fd4SBrian Somers  *    documentation and/or other materials provided with the distribution.
1530949fd4SBrian Somers  *
1630949fd4SBrian Somers  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1730949fd4SBrian Somers  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1830949fd4SBrian Somers  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1930949fd4SBrian Somers  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2030949fd4SBrian Somers  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2130949fd4SBrian Somers  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2230949fd4SBrian Somers  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2330949fd4SBrian Somers  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2430949fd4SBrian Somers  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2530949fd4SBrian Somers  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2630949fd4SBrian Somers  * SUCH DAMAGE.
2730949fd4SBrian Somers  */
2830949fd4SBrian Somers 
2930949fd4SBrian Somers /*
3030949fd4SBrian Somers  * These structures should be treated as opaque.
3130949fd4SBrian Somers  */
3230949fd4SBrian Somers struct ncprange {
3330949fd4SBrian Somers   sa_family_t ncprange_family;
3430949fd4SBrian Somers   union {
3530949fd4SBrian Somers     struct {
3630949fd4SBrian Somers       struct in_addr ipaddr;
3730949fd4SBrian Somers       struct in_addr mask;
3830949fd4SBrian Somers       int width;
3930949fd4SBrian Somers     } ip4;
4030949fd4SBrian Somers #ifndef NOINET6
4130949fd4SBrian Somers     struct {
4230949fd4SBrian Somers       struct in6_addr ipaddr;
4330949fd4SBrian Somers       int width;
4430949fd4SBrian Somers     } ip6;
4530949fd4SBrian Somers #endif
4630949fd4SBrian Somers   } u;
4730949fd4SBrian Somers };
4830949fd4SBrian Somers 
4930949fd4SBrian Somers struct ncpaddr {
5030949fd4SBrian Somers   sa_family_t ncpaddr_family;
5130949fd4SBrian Somers   union {
5230949fd4SBrian Somers     struct in_addr ip4addr;
5330949fd4SBrian Somers #ifndef NOINET6
5430949fd4SBrian Somers     struct in6_addr ip6addr;
5530949fd4SBrian Somers #endif
5630949fd4SBrian Somers   } u;
5730949fd4SBrian Somers };
5830949fd4SBrian Somers 
5930949fd4SBrian Somers struct ncp;
6030949fd4SBrian Somers 
6130949fd4SBrian Somers extern void ncpaddr_init(struct ncpaddr *);
625ae08329SBrian Somers extern int ncpaddr_isset(const struct ncpaddr *);
6330949fd4SBrian Somers extern int ncpaddr_isdefault(const struct ncpaddr *);
6430949fd4SBrian Somers extern int ncpaddr_equal(const struct ncpaddr *, const struct ncpaddr *);
6530949fd4SBrian Somers extern void ncpaddr_copy(struct ncpaddr *, const struct ncpaddr *);
6630949fd4SBrian Somers extern void ncpaddr_setip4addr(struct ncpaddr *, u_int32_t);
6730949fd4SBrian Somers extern int ncpaddr_getip4addr(const struct ncpaddr *, u_int32_t *);
6830949fd4SBrian Somers extern void ncpaddr_setip4(struct ncpaddr *, struct in_addr);
6930949fd4SBrian Somers extern int ncpaddr_getip4(const struct ncpaddr *, struct in_addr *);
7030949fd4SBrian Somers #ifndef NOINET6
7130949fd4SBrian Somers extern void ncpaddr_setip6(struct ncpaddr *, const struct in6_addr *);
7230949fd4SBrian Somers extern int ncpaddr_getip6(const struct ncpaddr *, struct in6_addr *);
7330949fd4SBrian Somers #endif
7430949fd4SBrian Somers extern void ncpaddr_getsa(const struct ncpaddr *, struct sockaddr_storage *);
7530949fd4SBrian Somers extern void ncpaddr_setsa(struct ncpaddr *, const struct sockaddr *);
7630949fd4SBrian Somers extern const char *ncpaddr_ntoa(const struct ncpaddr *);
7730949fd4SBrian Somers extern int ncpaddr_aton(struct ncpaddr *, struct ncp *, const char *);
7830949fd4SBrian Somers 
7930949fd4SBrian Somers extern void ncprange_init(struct ncprange *);
8030949fd4SBrian Somers extern int ncprange_isset(const struct ncprange *);
8130949fd4SBrian Somers extern int ncprange_equal(const struct ncprange *, const struct ncprange *);
8230949fd4SBrian Somers extern int ncprange_isdefault(const struct ncprange *);
8330949fd4SBrian Somers extern void ncprange_setdefault(struct ncprange *, int);
8430949fd4SBrian Somers extern int ncprange_contains(const struct ncprange *, const struct ncpaddr *);
8530949fd4SBrian Somers extern int ncprange_containsip4(const struct ncprange *, struct in_addr);
8630949fd4SBrian Somers extern void ncprange_copy(struct ncprange *, const struct ncprange *);
8730949fd4SBrian Somers extern void ncprange_set(struct ncprange *, const struct ncpaddr *, int);
8830949fd4SBrian Somers extern void ncprange_sethost(struct ncprange *, const struct ncpaddr *);
8926dceef0SBrian Somers extern int ncprange_ishost(const struct ncprange *);
9030949fd4SBrian Somers extern int ncprange_setwidth(struct ncprange *, int);
9130949fd4SBrian Somers extern void ncprange_setip4(struct ncprange *, struct in_addr, struct in_addr);
9230949fd4SBrian Somers extern void ncprange_setip4host(struct ncprange *, struct in_addr);
9330949fd4SBrian Somers extern int ncprange_setip4mask(struct ncprange *, struct in_addr);
9430949fd4SBrian Somers extern void ncprange_setsa(struct ncprange *, const struct sockaddr *,
9530949fd4SBrian Somers                            const struct sockaddr *);
9630949fd4SBrian Somers extern void ncprange_getsa(const struct ncprange *, struct sockaddr_storage *,
9730949fd4SBrian Somers                            struct sockaddr_storage *);
9830949fd4SBrian Somers extern int ncprange_getaddr(const struct ncprange *, struct ncpaddr *);
9930949fd4SBrian Somers extern int ncprange_getip4addr(const struct ncprange *, struct in_addr *);
10030949fd4SBrian Somers extern int ncprange_getip4mask(const struct ncprange *, struct in_addr *);
10130949fd4SBrian Somers extern int ncprange_getwidth(const struct ncprange *, int *);
10230949fd4SBrian Somers extern const char *ncprange_ntoa(const struct ncprange *);
10330949fd4SBrian Somers #ifndef NOINET6
10430949fd4SBrian Somers extern int ncprange_scopeid(const struct ncprange *);
10530949fd4SBrian Somers #endif
10630949fd4SBrian Somers extern int ncprange_aton(struct ncprange *, struct ncp *, const char *);
10730949fd4SBrian Somers 
10830949fd4SBrian Somers #define ncpaddr_family(a) ((a)->ncpaddr_family)
10930949fd4SBrian Somers #define ncprange_family(r) ((r)->ncprange_family)
110