]>
Commit | Line | Data |
---|---|---|
fe18ee2d DS |
1 | /* zebra NS Routines |
2 | * Copyright (C) 2016 Cumulus Networks, Inc. | |
3 | * Donald Sharp | |
4 | * | |
5 | * This file is part of Quagga. | |
6 | * | |
7 | * Quagga is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2, or (at your option) any | |
10 | * later version. | |
11 | * | |
12 | * Quagga is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with Quagga; see the file COPYING. If not, write to the Free | |
19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
20 | * 02111-1307, USA. | |
21 | */ | |
22 | #include "zebra.h" | |
23 | ||
13460c44 | 24 | #include "lib/ns.h" |
fe18ee2d DS |
25 | #include "lib/vrf.h" |
26 | #include "lib/prefix.h" | |
27 | #include "lib/memory.h" | |
28 | ||
29 | #include "rtadv.h" | |
30 | #include "zebra_ns.h" | |
7c551956 | 31 | #include "zebra_vrf.h" |
4a1ab8e4 DL |
32 | #include "zebra_memory.h" |
33 | ||
34 | DEFINE_MTYPE(ZEBRA, ZEBRA_NS, "Zebra Name Space") | |
35 | DEFINE_MTYPE(ZEBRA, NETLINK_NAME, "Netlink name") | |
fe18ee2d DS |
36 | |
37 | struct zebra_ns *dzns; | |
38 | ||
39 | struct zebra_ns * | |
40 | zebra_ns_lookup (ns_id_t ns_id) | |
41 | { | |
42 | return dzns; | |
43 | } | |
44 | ||
45 | int | |
46 | zebra_ns_enable (ns_id_t ns_id, void **info) | |
47 | { | |
48 | struct zebra_ns *zns = (struct zebra_ns *) (*info); | |
49 | #ifdef HAVE_NETLINK | |
50 | char nl_name[64]; | |
51 | #endif | |
52 | ||
53 | #if defined (HAVE_RTADV) | |
54 | rtadv_init (zns); | |
55 | #endif | |
56 | ||
57 | #ifdef HAVE_NETLINK | |
58 | /* Initialize netlink sockets */ | |
59 | snprintf (nl_name, 64, "netlink-listen (NS %u)", ns_id); | |
60 | zns->netlink.sock = -1; | |
61 | zns->netlink.name = XSTRDUP (MTYPE_NETLINK_NAME, nl_name); | |
62 | ||
63 | snprintf (nl_name, 64, "netlink-cmd (NS %u)", ns_id); | |
64 | zns->netlink_cmd.sock = -1; | |
65 | zns->netlink_cmd.name = XSTRDUP (MTYPE_NETLINK_NAME, nl_name); | |
66 | #endif | |
67 | zns->if_table = route_table_init (); | |
68 | kernel_init (zns); | |
69 | interface_list (zns); | |
70 | route_read (zns); | |
71 | ||
72 | return 0; | |
73 | } | |
74 | ||
75 | int | |
76 | zebra_ns_disable (ns_id_t ns_id, void **info) | |
77 | { | |
78 | struct zebra_ns *zns = (struct zebra_ns *) (*info); | |
79 | ||
80 | #if defined (HAVE_RTADV) | |
81 | rtadv_terminate (zns); | |
82 | #endif | |
83 | ||
84 | kernel_terminate (zns); | |
85 | ||
86 | return 0; | |
87 | } | |
88 | ||
89 | int | |
90 | zebra_ns_init (void) | |
91 | { | |
92 | dzns = XCALLOC (MTYPE_ZEBRA_NS, sizeof (struct zebra_ns)); | |
93 | ||
13460c44 FL |
94 | ns_init (); |
95 | ||
fe18ee2d DS |
96 | zebra_vrf_init (); |
97 | ||
98 | zebra_ns_enable (0, (void **)&dzns); | |
99 | ||
100 | return 0; | |
101 | } |