xref: /dragonfly/sys/netproto/mpls/mpls.h (revision f2c43266)
1 /*
2  * Copyright (c) 2007 The DragonFly Project.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
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
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  * 3. Neither the name of The DragonFly Project nor the names of its
15  *    contributors may be used to endorse or promote products derived
16  *    from this software without specific, prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  * $DragonFly: src/sys/netproto/mpls/mpls.h,v 1.2 2008/07/07 23:11:54 nant Exp $
32  */
33 
34 #ifndef _NETMPLS_MPLS_H_
35 #define _NETMPLS_MPLS_H_
36 
37 #include <arpa/inet.h>
38 
39 #include <sys/types.h>
40 
41 typedef u_int32_t	mpls_label_t;
42 typedef u_int8_t	mpls_exp_t;
43 typedef u_int8_t	mpls_s_t;
44 typedef u_int8_t	mpls_ttl_t;
45 
46 struct mpls {
47 	u_int32_t	mpls_shim;
48 };
49 #define MPLS_LABEL_MASK		0xfffff000
50 #define MPLS_EXP_MASK		0x00000e00
51 #define MPLS_STACK_MASK		0x00000100
52 #define MPLS_TTL_MASK		0x000000ff
53 #define MPLS_LABEL(shim)	(((shim) & MPLS_LABEL_MASK) >> 12)
54 #define MPLS_EXP(shim)		(((shim) & MPLS_EXP_MASK) >> 9)
55 #define MPLS_STACK(shim)	(((shim) & MPLS_STACK_MASK) >> 8)
56 #define MPLS_TTL(shim)		((shim) & MPLS_TTL_MASK)
57 #define MPLS_SET_LABEL(shim, x)					\
58 		do {						\
59 			shim &= ~MPLS_LABEL_MASK;		\
60 			shim |= ((x) << 12) & MPLS_LABEL_MASK;	\
61 		} while(0)
62 #define MPLS_SET_EXP(shim, x)					\
63 		do {						\
64 			shim &= ~MPLS_EXP_MASK;			\
65 			shim |= ((x) << 9) & MPLS_EXP_MASK;	\
66 		} while(0)
67 #define MPLS_SET_STACK(shim, x)					\
68 		do {						\
69 			shim &= ~MPLS_STACK_MASK;			\
70 			shim |= ((x) << 8) & MPLS_STACK_MASK;	\
71 		} while(0)
72 #define MPLS_SET_TTL(shim, x)					\
73 		do {						\
74 			shim &= ~MPLS_TTL_MASK;			\
75 			shim |= (x) & MPLS_TTL_MASK;		\
76 		} while(0)
77 
78 struct	mpls_addr {
79 	mpls_label_t	ma_label;
80 };
81 
82 struct	sockaddr_mpls {
83 	u_int8_t		smpls_len;
84 	u_int8_t		smpls_family;
85 	u_int8_t		smpls_op;	/* label op. push, pop, swap */
86 	mpls_exp_t		smpls_exp;
87 	struct mpls_addr	smpls_addr;
88 };
89 #define	smpls_label	smpls_addr.ma_label
90 
91 #define MPLSLOP_PUSH	1
92 #define MPLSLOP_POP	2
93 #define MPLSLOP_SWAP	3
94 #define MPLSLOP_POPALL	4
95 
96 #define MPLS_MAXLOPS	3
97 
98 /*
99  * Definitions for mpls sysctl operations.
100  */
101 #define CTL_MPLSPROTO_NAMES {		\
102 	{ "mpls", CTLTYPE_NODE },	\
103 	{0, 0}				\
104 }
105 
106 /*
107  * Names for MPLS sysctl objects.
108  */
109 #define MPLSCTL_FORWARDING	1
110 
111 #endif /* _NETMPLS_MPLS_H_ */
112 
113