Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/ip_carp.c
Show All 40 Lines | |||||
#include <sys/jail.h> | #include <sys/jail.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/limits.h> | #include <sys/limits.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/mbuf.h> | #include <sys/mbuf.h> | ||||
#include <sys/module.h> | #include <sys/module.h> | ||||
#include <sys/priv.h> | #include <sys/priv.h> | ||||
#include <sys/proc.h> | #include <sys/proc.h> | ||||
#include <sys/protosw.h> | |||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
#include <sys/sockio.h> | #include <sys/sockio.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/syslog.h> | #include <sys/syslog.h> | ||||
#include <sys/taskqueue.h> | #include <sys/taskqueue.h> | ||||
#include <sys/counter.h> | #include <sys/counter.h> | ||||
#include <net/ethernet.h> | #include <net/ethernet.h> | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | #ifdef INET6 | ||||
struct ip6_moptions cif_im6o; | struct ip6_moptions cif_im6o; | ||||
#endif | #endif | ||||
struct ifnet *cif_ifp; | struct ifnet *cif_ifp; | ||||
struct mtx cif_mtx; | struct mtx cif_mtx; | ||||
uint32_t cif_flags; | uint32_t cif_flags; | ||||
#define CIF_PROMISC 0x00000001 | #define CIF_PROMISC 0x00000001 | ||||
}; | }; | ||||
#define CARP_INET 0 | |||||
#define CARP_INET6 1 | |||||
static int proto_reg[] = {-1, -1}; | |||||
/* | /* | ||||
* Brief design of carp(4). | * Brief design of carp(4). | ||||
* | * | ||||
* Any carp-capable ifnet may have a list of carp softcs hanging off | * Any carp-capable ifnet may have a list of carp softcs hanging off | ||||
* its ifp->if_carp pointer. Each softc represents one unique virtual | * its ifp->if_carp pointer. Each softc represents one unique virtual | ||||
* host id, or vhid. The softc has a back pointer to the ifnet. All | * host id, or vhid. The softc has a back pointer to the ifnet. All | ||||
* softcs are joined in a global list, which has quite limited use. | * softcs are joined in a global list, which has quite limited use. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 282 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/* | /* | ||||
* process input packet. | * process input packet. | ||||
* we have rearranged checks order compared to the rfc, | * we have rearranged checks order compared to the rfc, | ||||
* but it seems more efficient this way or not possible otherwise. | * but it seems more efficient this way or not possible otherwise. | ||||
*/ | */ | ||||
#ifdef INET | #ifdef INET | ||||
int | static int | ||||
carp_input(struct mbuf **mp, int *offp, int proto) | carp_input(struct mbuf **mp, int *offp, int proto) | ||||
{ | { | ||||
struct mbuf *m = *mp; | struct mbuf *m = *mp; | ||||
struct ip *ip = mtod(m, struct ip *); | struct ip *ip = mtod(m, struct ip *); | ||||
struct carp_header *ch; | struct carp_header *ch; | ||||
int iplen, len; | int iplen, len; | ||||
iplen = *offp; | iplen = *offp; | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | carp_input(struct mbuf **mp, int *offp, int proto) | ||||
m->m_data -= iplen; | m->m_data -= iplen; | ||||
carp_input_c(m, ch, AF_INET); | carp_input_c(m, ch, AF_INET); | ||||
return (IPPROTO_DONE); | return (IPPROTO_DONE); | ||||
} | } | ||||
#endif | #endif | ||||
#ifdef INET6 | #ifdef INET6 | ||||
int | static int | ||||
carp6_input(struct mbuf **mp, int *offp, int proto) | carp6_input(struct mbuf **mp, int *offp, int proto) | ||||
{ | { | ||||
struct mbuf *m = *mp; | struct mbuf *m = *mp; | ||||
struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); | struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); | ||||
struct carp_header *ch; | struct carp_header *ch; | ||||
u_int len; | u_int len; | ||||
CARPSTATS_INC(carps_ipackets6); | CARPSTATS_INC(carps_ipackets6); | ||||
▲ Show 20 Lines • Show All 1,620 Lines • ▼ Show 20 Lines | carp_demote_adj_sysctl(SYSCTL_HANDLER_ARGS) | ||||
if (error || !req->newptr) | if (error || !req->newptr) | ||||
return (error); | return (error); | ||||
carp_demote_adj(new, "sysctl"); | carp_demote_adj(new, "sysctl"); | ||||
return (0); | return (0); | ||||
} | } | ||||
#ifdef INET | |||||
extern struct domain inetdomain; | |||||
static struct protosw in_carp_protosw = { | |||||
.pr_type = SOCK_RAW, | |||||
.pr_domain = &inetdomain, | |||||
.pr_protocol = IPPROTO_CARP, | |||||
.pr_flags = PR_ATOMIC|PR_ADDR, | |||||
.pr_input = carp_input, | |||||
.pr_ctloutput = rip_ctloutput, | |||||
.pr_usrreqs = &rip_usrreqs | |||||
}; | |||||
#endif | |||||
#ifdef INET6 | |||||
extern struct domain inet6domain; | |||||
static struct protosw in6_carp_protosw = { | |||||
.pr_type = SOCK_RAW, | |||||
.pr_domain = &inet6domain, | |||||
.pr_protocol = IPPROTO_CARP, | |||||
.pr_flags = PR_ATOMIC|PR_ADDR, | |||||
.pr_input = carp6_input, | |||||
.pr_ctloutput = rip6_ctloutput, | |||||
.pr_usrreqs = &rip6_usrreqs | |||||
}; | |||||
#endif | |||||
static void | static void | ||||
carp_mod_cleanup(void) | carp_mod_cleanup(void) | ||||
{ | { | ||||
#ifdef INET | #ifdef INET | ||||
if (proto_reg[CARP_INET] == 0) { | |||||
(void)ipproto_unregister(IPPROTO_CARP); | (void)ipproto_unregister(IPPROTO_CARP); | ||||
pf_proto_unregister(PF_INET, IPPROTO_CARP, SOCK_RAW); | |||||
proto_reg[CARP_INET] = -1; | |||||
} | |||||
carp_iamatch_p = NULL; | carp_iamatch_p = NULL; | ||||
#endif | #endif | ||||
#ifdef INET6 | #ifdef INET6 | ||||
if (proto_reg[CARP_INET6] == 0) { | |||||
(void)ip6proto_unregister(IPPROTO_CARP); | (void)ip6proto_unregister(IPPROTO_CARP); | ||||
pf_proto_unregister(PF_INET6, IPPROTO_CARP, SOCK_RAW); | |||||
proto_reg[CARP_INET6] = -1; | |||||
} | |||||
carp_iamatch6_p = NULL; | carp_iamatch6_p = NULL; | ||||
carp_macmatch6_p = NULL; | carp_macmatch6_p = NULL; | ||||
#endif | #endif | ||||
carp_ioctl_p = NULL; | carp_ioctl_p = NULL; | ||||
carp_attach_p = NULL; | carp_attach_p = NULL; | ||||
carp_detach_p = NULL; | carp_detach_p = NULL; | ||||
carp_get_vhid_p = NULL; | carp_get_vhid_p = NULL; | ||||
carp_linkstate_p = NULL; | carp_linkstate_p = NULL; | ||||
Show All 22 Lines | carp_mod_load(void) | ||||
carp_ioctl_p = carp_ioctl; | carp_ioctl_p = carp_ioctl; | ||||
carp_attach_p = carp_attach; | carp_attach_p = carp_attach; | ||||
carp_detach_p = carp_detach; | carp_detach_p = carp_detach; | ||||
carp_demote_adj_p = carp_demote_adj; | carp_demote_adj_p = carp_demote_adj; | ||||
carp_master_p = carp_master; | carp_master_p = carp_master; | ||||
#ifdef INET6 | #ifdef INET6 | ||||
carp_iamatch6_p = carp_iamatch6; | carp_iamatch6_p = carp_iamatch6; | ||||
carp_macmatch6_p = carp_macmatch6; | carp_macmatch6_p = carp_macmatch6; | ||||
proto_reg[CARP_INET6] = pf_proto_register(PF_INET6, | err = ip6proto_register(IPPROTO_CARP, carp6_input, NULL); | ||||
(struct protosw *)&in6_carp_protosw); | |||||
if (proto_reg[CARP_INET6]) { | |||||
printf("carp: error %d attaching to PF_INET6\n", | |||||
proto_reg[CARP_INET6]); | |||||
carp_mod_cleanup(); | |||||
return (proto_reg[CARP_INET6]); | |||||
} | |||||
err = ip6proto_register(IPPROTO_CARP); | |||||
if (err) { | if (err) { | ||||
printf("carp: error %d registering with INET6\n", err); | printf("carp: error %d registering with INET6\n", err); | ||||
carp_mod_cleanup(); | carp_mod_cleanup(); | ||||
return (err); | return (err); | ||||
} | } | ||||
#endif | #endif | ||||
#ifdef INET | #ifdef INET | ||||
carp_iamatch_p = carp_iamatch; | carp_iamatch_p = carp_iamatch; | ||||
proto_reg[CARP_INET] = pf_proto_register(PF_INET, &in_carp_protosw); | err = ipproto_register(IPPROTO_CARP, carp_input, NULL); | ||||
if (proto_reg[CARP_INET]) { | |||||
printf("carp: error %d attaching to PF_INET\n", | |||||
proto_reg[CARP_INET]); | |||||
carp_mod_cleanup(); | |||||
return (proto_reg[CARP_INET]); | |||||
} | |||||
err = ipproto_register(IPPROTO_CARP); | |||||
if (err) { | if (err) { | ||||
printf("carp: error %d registering with INET\n", err); | printf("carp: error %d registering with INET\n", err); | ||||
carp_mod_cleanup(); | carp_mod_cleanup(); | ||||
return (err); | return (err); | ||||
} | } | ||||
#endif | #endif | ||||
return (0); | return (0); | ||||
} | } | ||||
Show All 32 Lines |