Commit Graph

103 Commits

Author SHA1 Message Date
Feng Lu
e5bf3e1ed7 lib/vrf: enable / disable a VRF
A new API vrf_is_enabled() is defined to check whether a VRF is ready
to use, that is, to allocate resources in that VRF. Currently there's
only one type of resource: socket.

Two new hooks VRF_ENABLE_HOOK/VRF_DISABLE_HOOK are introduced to tell
the user when a VRF gets ready or to be unavailable.

The VRF_ENABLE_HOOK callback is called in the new function vrf_enable(),
which is used to let the VRF be ready to use. Till now, only the default
VRF can be enabled, and we need do nothing to enable the default, except
calling the hook.

The VRF_DISABLE_HOOK callback is called in the new function
vrf_disable(), which is used to let the VRF be unusable. Till now,
it is called only when the VRF is to be deleted.

A new utility vrf_socket() is defined to provide a socket in a given
VRF to the user.

Till now before introducing a way of VRF realization, only the default
VRF is enabled since its birth, and vrf_socket() creates socket for
only the default VRF.

This patch defines the framework of the VRF APIs. The way they serve
the users is:
- vrf_is_enabled() is used to tell the user whether a VRF is usable;
- users are informed by the VRF_ENABLE_HOOK that a VRF gets usable;
  they can allocate resources after that;
- users are informed by the VRF_DISABLE_HOOK that a VRF is to be
  unavailable, and they must release the resources instantly;
- vrf_socket() is used to provide a socket in a given VRF.

Signed-off-by: Feng Lu <lu.feng@6wind.com>
Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Acked-by: Vincent JARDIN <vincent.jardin@6wind.com>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2015-10-30 00:29:10 -07:00
Feng Lu
8736158a2b lib: move the interface list into "struct vrf"
An interface belongs to a specific VRF. So move the interface list
into the "struct vrf".

* vrf.c/vrf.h:
  - add a new member "struct list *iflist" to the the "struct vrf";
  - call if_init() in vrf_new();
  - call if_terminate() in vrf_delete();
  - add utilities to access the interface list and VRF ID in the
    specified VRF.

* if.c/if.h:
  - the global "iflist" now only exists for the default VRF;
  - the global "if_master" is initialized on the definition;
  - in if_create(), the interface is added into the list in the
    specified VRF; if the VRF does not exist, create one;
  - add parameters to if_init()/if_terminate() so that the
    interface list in the VRF can be initialized/destroyed;
  - in if_dump_all() scan the interfaces in all the VRFs;
  - add a command "show address vrf N" to show addresses in a
    specified VRF;
  - add a command "show address vrf all" to show addresses in all
    VRFs;
  - new APIs ifxxx_vrf() are added to access an interface in a
    specified VRF.

The old interface APIs (the global variable "iflist" and the API
functions) are not changed to keep the backward compatibility.
The new APIs are used in the daemons which support multiple VRFs
(till now only zebra).

Signed-off-by: Feng Lu <lu.feng@6wind.com>
Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Acked-by: Vincent JARDIN <vincent.jardin@6wind.com>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>

Conflicts:
	lib/if.c
2015-10-29 17:25:55 -07:00
Feng Lu
b72ede27fd lib, zebra: move "struct vrf" to be a lib module
Previously "struct vrf" is defined locally in zebra. Now it is moved
to be a lib module.

This is the first step to support multi-VRF in quagga. The
implementation is splitted into small patches for the purpose of
easy review.

* lib:
    "struct vrf" with basic members is defined in vrf.c. The member
    "void *info" is for user data.

    Some basic functions are defined in vrf.c for adding/deleting/
    looking up a VRF, scanning the VRF table and initializing the
    VRF module.

    The type "vrf_id_t" is defined specificly for VRF ID.

* zebra:
    The previous "struct vrf" is re-defined as "struct zebra_vrf";
    and previous "vrf" variables are renamed to "zvrf".

    The previous "struct vrf" related functions are removed from
    zbera_rib.c. New functions are defined to maintain the new
    "struct zebra_vrf".

    The names vrf_xxx are reserved for the functions in VRF module.
    So:
    - the previous vrf_table() are renamed to zebra_vrf_table();
    - the previous vrf_static_table() are renamed to
      zebra_vrf_static_table().

    The main logic is not changed.

    BTW: Add a statement to zebra_snmp.c telling that the SNMP is
         running only for the MIBs in the default VRF.

Signed-off-by: Feng Lu <lu.feng@6wind.com>
Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Acked-by: Vincent JARDIN <vincent.jardin@6wind.com>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>

Conflicts:
	lib/Makefile.am
	zebra/zebra_rib.c
	zebra/zebra_vty.c

Conflicts:
	lib/Makefile.am
	lib/memtypes.c
	zebra/rib.h
	zebra/zebra_rib.c
	zebra/zebra_rnh.c
	zebra/zebra_rnh.h
	zebra/zebra_vty.c
2015-10-29 16:45:10 -07:00