Introduce experimental MPLS over ethernet support. Add 'options MPLS'
[dragonfly.git] / sys / netproto / mpls / mpls.h
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.1 2008/07/07 22:02:10 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 /* should any of the folowing be moved to sys/types.h? */
42 typedef u_int32_t       mpls_label_t;
43 typedef u_int8_t        mpls_exp_t;
44 typedef u_int8_t        mpls_s_t;
45 typedef u_int8_t        mpls_ttl_t;
46
47 struct mpls {
48         u_int32_t       mpls_shim;
49 };
50 #define MPLS_LABEL_MASK         0xfffff000
51 #define MPLS_EXP_MASK           0x00000e00
52 #define MPLS_STACK_MASK         0x00000100
53 #define MPLS_TTL_MASK           0x000000ff
54 #define MPLS_LABEL(shim)        (((shim) & MPLS_LABEL_MASK) >> 12)
55 #define MPLS_EXP(shim)          (((shim) & MPLS_EXP_MASK) >> 9)
56 #define MPLS_STACK(shim)        (((shim) & MPLS_STACK_MASK) >> 8)
57 #define MPLS_TTL(shim)          ((shim) & MPLS_TTL_MASK)
58 #define MPLS_SET_LABEL(shim, x)                                 \
59                 do {                                            \
60                         shim &= ~MPLS_LABEL_MASK;               \
61                         shim |= ((x) << 12) & MPLS_LABEL_MASK;  \
62                 } while(0)
63 #define MPLS_SET_EXP(shim, x)                                   \
64                 do {                                            \
65                         shim &= ~MPLS_EXP_MASK;                 \
66                         shim |= ((x) << 9) & MPLS_EXP_MASK;     \
67                 } while(0)
68 #define MPLS_SET_STACK(shim, x)                                 \
69                 do {                                            \
70                         shim &= ~MPLS_STACK_MASK;                       \
71                         shim |= ((x) << 8) & MPLS_STACK_MASK;   \
72                 } while(0)
73 #define MPLS_SET_TTL(shim, x)                                   \
74                 do {                                            \
75                         shim &= ~MPLS_TTL_MASK;                 \
76                         shim |= (x) & MPLS_TTL_MASK;            \
77                 } while(0)
78
79 struct  mpls_addr {
80         mpls_label_t    ma_label;
81 };
82
83 struct  sockaddr_mpls {
84         u_int8_t                smpls_len;
85         u_int8_t                smpls_family;
86         u_int8_t                smpls_op;       /* label op. push, pop, swap */
87         mpls_exp_t              smpls_exp;
88         struct mpls_addr        smpls_addr;
89 };
90 #define smpls_label     smpls_addr.ma_label
91
92 #define MPLSLOP_PUSH    1
93 #define MPLSLOP_POP     2
94 #define MPLSLOP_SWAP    3
95 #define MPLSLOP_POPALL  4
96
97 #define MPLS_MAXLOPS    3
98
99 /*
100  * Definitions for mpls sysctl operations.
101  */
102 #define CTL_MPLSPROTO_NAMES {           \
103         { "mpls", CTLTYPE_NODE },       \
104         {0, 0}                          \
105 }
106
107 /*
108  * Names for MPLS sysctl objects.
109  */
110 #define MPLSCTL_FORWARDING      1
111
112 #endif /* _NETMPLS_MPLS_H_ */
113