19b42cabeSNuno Antunes /*
29b42cabeSNuno Antunes * Copyright (c) 2007 The DragonFly Project. All rights reserved.
39b42cabeSNuno Antunes *
49b42cabeSNuno Antunes * Redistribution and use in source and binary forms, with or without
59b42cabeSNuno Antunes * modification, are permitted provided that the following conditions
69b42cabeSNuno Antunes * are met:
79b42cabeSNuno Antunes *
89b42cabeSNuno Antunes * 1. Redistributions of source code must retain the above copyright
99b42cabeSNuno Antunes * notice, this list of conditions and the following disclaimer.
109b42cabeSNuno Antunes * 2. Redistributions in binary form must reproduce the above copyright
119b42cabeSNuno Antunes * notice, this list of conditions and the following disclaimer in
129b42cabeSNuno Antunes * the documentation and/or other materials provided with the
139b42cabeSNuno Antunes * distribution.
149b42cabeSNuno Antunes * 3. Neither the name of The DragonFly Project nor the names of its
159b42cabeSNuno Antunes * contributors may be used to endorse or promote products derived
169b42cabeSNuno Antunes * from this software without specific, prior written permission.
179b42cabeSNuno Antunes *
189b42cabeSNuno Antunes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
199b42cabeSNuno Antunes * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
209b42cabeSNuno Antunes * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
219b42cabeSNuno Antunes * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
229b42cabeSNuno Antunes * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
239b42cabeSNuno Antunes * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
249b42cabeSNuno Antunes * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
259b42cabeSNuno Antunes * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
269b42cabeSNuno Antunes * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
279b42cabeSNuno Antunes * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
289b42cabeSNuno Antunes * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
299b42cabeSNuno Antunes * SUCH DAMAGE.
309b42cabeSNuno Antunes */
319b42cabeSNuno Antunes
329b42cabeSNuno Antunes #include <sys/domain.h>
339b42cabeSNuno Antunes #include <sys/kernel.h> /* SYSINIT via DOMAIN_SET */
349b42cabeSNuno Antunes #include <sys/protosw.h>
359b42cabeSNuno Antunes #include <sys/socket.h>
36f3834e0dSSepherosa Ziehau #include <sys/globaldata.h>
37f3834e0dSSepherosa Ziehau #include <sys/thread.h>
389b42cabeSNuno Antunes
399b42cabeSNuno Antunes #include <net/radix.h> /* rn_inithead */
409b42cabeSNuno Antunes
419b42cabeSNuno Antunes #include <netproto/mpls/mpls.h>
429b42cabeSNuno Antunes #include <netproto/mpls/mpls_var.h>
439b42cabeSNuno Antunes
449b42cabeSNuno Antunes /* forward declarations */
459b42cabeSNuno Antunes static struct domain mplsdomain;
469b42cabeSNuno Antunes static struct pr_usrreqs nousrreqs; /* XXX use this for something */
479b42cabeSNuno Antunes
489b42cabeSNuno Antunes struct protosw mplssw[] = {
4967bf99c4SMatthew Dillon {
5067bf99c4SMatthew Dillon .pr_type = 0,
5167bf99c4SMatthew Dillon .pr_domain = &mplsdomain,
5267bf99c4SMatthew Dillon
5367bf99c4SMatthew Dillon .pr_init = mpls_init,
5467bf99c4SMatthew Dillon .pr_usrreqs = &nousrreqs
559b42cabeSNuno Antunes },
5667bf99c4SMatthew Dillon {
5767bf99c4SMatthew Dillon .pr_type = SOCK_RAW,
5867bf99c4SMatthew Dillon .pr_domain = &mplsdomain,
5967bf99c4SMatthew Dillon .pr_protocol = 0,
6067bf99c4SMatthew Dillon .pr_flags = PR_ATOMIC|PR_ADDR,
6167bf99c4SMatthew Dillon
6267bf99c4SMatthew Dillon .pr_usrreqs = &nousrreqs
6367bf99c4SMatthew Dillon }
649b42cabeSNuno Antunes };
659b42cabeSNuno Antunes
66f3834e0dSSepherosa Ziehau static int
mpls_inithead(void ** head,int off)67f3834e0dSSepherosa Ziehau mpls_inithead(void **head, int off)
68f3834e0dSSepherosa Ziehau {
696823c302SAaron LI struct radix_node_head *rnh;
706823c302SAaron LI
716823c302SAaron LI rnh = *head;
72*500d7b86SAaron LI KKASSERT(rnh == rt_tables[mycpuid][AF_MPLS]);
736823c302SAaron LI
746823c302SAaron LI if (!rn_inithead(&rnh, rn_cpumaskhead(mycpuid), off))
756823c302SAaron LI return 0;
766823c302SAaron LI
776823c302SAaron LI *head = rnh;
786823c302SAaron LI return 1;
79f3834e0dSSepherosa Ziehau }
80f3834e0dSSepherosa Ziehau
819b42cabeSNuno Antunes static struct domain mplsdomain = {
82a4f40cc8SAaron LI .dom_family = AF_MPLS,
83a4f40cc8SAaron LI .dom_name = "mpls",
84a4f40cc8SAaron LI .dom_init = NULL,
85a4f40cc8SAaron LI .dom_externalize = NULL,
86a4f40cc8SAaron LI .dom_dispose = NULL,
87a4f40cc8SAaron LI .dom_protosw = mplssw,
88a4f40cc8SAaron LI .dom_protoswNPROTOSW = &mplssw[NELEM(mplssw)],
89a4f40cc8SAaron LI .dom_next = SLIST_ENTRY_INITIALIZER,
90a4f40cc8SAaron LI .dom_rtattach = mpls_inithead,
91a4f40cc8SAaron LI .dom_rtoffset = offsetof(struct sockaddr_mpls, smpls_addr),
92a4f40cc8SAaron LI .dom_maxrtkey = sizeof(struct sockaddr_mpls),
93a4f40cc8SAaron LI .dom_ifattach = NULL,
94a4f40cc8SAaron LI .dom_ifdetach = NULL,
95a4f40cc8SAaron LI .dom_if_up = NULL,
96a4f40cc8SAaron LI .dom_if_down = NULL,
979b42cabeSNuno Antunes };
989b42cabeSNuno Antunes
999b42cabeSNuno Antunes DOMAIN_SET(mpls);
1009b42cabeSNuno Antunes
1019b42cabeSNuno Antunes #if 0
1029b42cabeSNuno Antunes SYSCTL_NODE(_net, PF_MPLS, mpls, CTLFLAG_RW, 0,
1039b42cabeSNuno Antunes "MPLS Family");
1049b42cabeSNuno Antunes #endif
1059b42cabeSNuno Antunes
106