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>
diff --git a/lib/if.h b/lib/if.h
index 029f57f..03bd521 100644
--- a/lib/if.h
+++ b/lib/if.h
@@ -249,17 +249,38 @@
extern struct interface *if_lookup_address (struct in_addr);
extern struct interface *if_lookup_prefix (struct prefix *prefix);
+extern struct interface *if_create_vrf (const char *name, int namelen,
+ vrf_id_t vrf_id);
+extern struct interface *if_lookup_by_index_vrf (unsigned int,
+ vrf_id_t vrf_id);
+extern struct interface *if_lookup_exact_address_vrf (struct in_addr,
+ vrf_id_t vrf_id);
+extern struct interface *if_lookup_address_vrf (struct in_addr,
+ vrf_id_t vrf_id);
+extern struct interface *if_lookup_prefix_vrf (struct prefix *prefix,
+ vrf_id_t vrf_id);
+
/* These 2 functions are to be used when the ifname argument is terminated
by a '\0' character: */
extern struct interface *if_lookup_by_name (const char *ifname);
extern struct interface *if_get_by_name (const char *ifname);
+extern struct interface *if_lookup_by_name_vrf (const char *ifname,
+ vrf_id_t vrf_id);
+extern struct interface *if_get_by_name_vrf (const char *ifname,
+ vrf_id_t vrf_id);
+
/* For these 2 functions, the namelen argument should be the precise length
of the ifname string (not counting any optional trailing '\0' character).
In most cases, strnlen should be used to calculate the namelen value. */
extern struct interface *if_lookup_by_name_len(const char *ifname,
- size_t namelen);
-extern struct interface *if_get_by_name_len(const char *ifname, size_t namelen);
+ size_t namelen);
+extern struct interface *if_get_by_name_len(const char *ifname,size_t namelen);
+
+extern struct interface *if_lookup_by_name_len_vrf(const char *ifname,
+ size_t namelen, vrf_id_t vrf_id);
+extern struct interface *if_get_by_name_len_vrf(const char *ifname,
+ size_t namelen, vrf_id_t vrf_id);
/* Delete the interface, but do not free the structure, and leave it in the
@@ -279,8 +300,8 @@
extern int if_is_pointopoint (struct interface *);
extern int if_is_multicast (struct interface *);
extern void if_add_hook (int, int (*)(struct interface *));
-extern void if_init (void);
-extern void if_terminate (void);
+extern void if_init (vrf_id_t, struct list **);
+extern void if_terminate (vrf_id_t, struct list **);
extern void if_dump_all (void);
extern const char *if_flag_dump(unsigned long);
@@ -288,11 +309,13 @@
ifindex2ifname uses internal interface info, whereas if_indextoname must
make a system call. */
extern const char *ifindex2ifname (unsigned int);
+extern const char *ifindex2ifname_vrf (unsigned int, vrf_id_t vrf_id);
/* Please use ifname2ifindex instead of if_nametoindex where possible;
ifname2ifindex uses internal interface info, whereas if_nametoindex must
make a system call. */
extern unsigned int ifname2ifindex(const char *ifname);
+extern unsigned int ifname2ifindex_vrf(const char *ifname, vrf_id_t vrf_id);
/* Connected address functions. */
extern struct connected *connected_new (void);
@@ -322,5 +345,7 @@
extern struct cmd_element interface_pseudo_cmd;
extern struct cmd_element no_interface_pseudo_cmd;
extern struct cmd_element show_address_cmd;
+extern struct cmd_element show_address_vrf_cmd;
+extern struct cmd_element show_address_vrf_all_cmd;
#endif /* _ZEBRA_IF_H */