Changeset View
Changeset View
Standalone View
Standalone View
sys/netpfil/pf/pf_lb.c
| Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
| #include <net/vnet.h> | #include <net/vnet.h> | ||||
| #include <net/pfvar.h> | #include <net/pfvar.h> | ||||
| #include <net/if_pflog.h> | #include <net/if_pflog.h> | ||||
| #define DPFPRINTF(n, x) if (V_pf_status.debug >= (n)) printf x | #define DPFPRINTF(n, x) if (V_pf_status.debug >= (n)) printf x | ||||
| static void pf_hash(struct pf_addr *, struct pf_addr *, | static void pf_hash(struct pf_addr *, struct pf_addr *, | ||||
| struct pf_poolhashkey *, sa_family_t); | struct pf_poolhashkey *, sa_family_t); | ||||
| static struct pf_rule *pf_match_translation(struct pf_pdesc *, struct mbuf *, | static struct pf_krule *pf_match_translation(struct pf_pdesc *, struct mbuf *, | ||||
| int, int, struct pfi_kif *, | int, int, struct pfi_kif *, | ||||
| struct pf_addr *, u_int16_t, struct pf_addr *, | struct pf_addr *, u_int16_t, struct pf_addr *, | ||||
| uint16_t, int, struct pf_anchor_stackframe *); | uint16_t, int, struct pf_kanchor_stackframe *); | ||||
| static int pf_get_sport(sa_family_t, uint8_t, struct pf_rule *, | static int pf_get_sport(sa_family_t, uint8_t, struct pf_krule *, | ||||
| struct pf_addr *, uint16_t, struct pf_addr *, uint16_t, struct pf_addr *, | struct pf_addr *, uint16_t, struct pf_addr *, uint16_t, struct pf_addr *, | ||||
| uint16_t *, uint16_t, uint16_t, struct pf_ksrc_node **); | uint16_t *, uint16_t, uint16_t, struct pf_ksrc_node **); | ||||
| #define mix(a,b,c) \ | #define mix(a,b,c) \ | ||||
| do { \ | do { \ | ||||
| a -= b; a -= c; a ^= (c >> 13); \ | a -= b; a -= c; a ^= (c >> 13); \ | ||||
| b -= c; b -= a; b ^= (a << 8); \ | b -= c; b -= a; b ^= (a << 8); \ | ||||
| c -= a; c -= b; c ^= (b >> 13); \ | c -= a; c -= b; c ^= (b >> 13); \ | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | case AF_INET6: | ||||
| c += key->key32[3]; | c += key->key32[3]; | ||||
| mix(a, b, c); | mix(a, b, c); | ||||
| hash->addr32[3] = c; | hash->addr32[3] = c; | ||||
| break; | break; | ||||
| #endif /* INET6 */ | #endif /* INET6 */ | ||||
| } | } | ||||
| } | } | ||||
| static struct pf_rule * | static struct pf_krule * | ||||
| pf_match_translation(struct pf_pdesc *pd, struct mbuf *m, int off, | pf_match_translation(struct pf_pdesc *pd, struct mbuf *m, int off, | ||||
| int direction, struct pfi_kif *kif, struct pf_addr *saddr, u_int16_t sport, | int direction, struct pfi_kif *kif, struct pf_addr *saddr, u_int16_t sport, | ||||
| struct pf_addr *daddr, uint16_t dport, int rs_num, | struct pf_addr *daddr, uint16_t dport, int rs_num, | ||||
| struct pf_anchor_stackframe *anchor_stack) | struct pf_kanchor_stackframe *anchor_stack) | ||||
| { | { | ||||
| struct pf_rule *r, *rm = NULL; | struct pf_krule *r, *rm = NULL; | ||||
| struct pf_ruleset *ruleset = NULL; | struct pf_kruleset *ruleset = NULL; | ||||
| int tag = -1; | int tag = -1; | ||||
| int rtableid = -1; | int rtableid = -1; | ||||
| int asd = 0; | int asd = 0; | ||||
| r = TAILQ_FIRST(pf_main_ruleset.rules[rs_num].active.ptr); | r = TAILQ_FIRST(pf_main_ruleset.rules[rs_num].active.ptr); | ||||
| while (r && rm == NULL) { | while (r && rm == NULL) { | ||||
| struct pf_rule_addr *src = NULL, *dst = NULL; | struct pf_rule_addr *src = NULL, *dst = NULL; | ||||
| struct pf_addr_wrap *xdst = NULL; | struct pf_addr_wrap *xdst = NULL; | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | pf_match_translation(struct pf_pdesc *pd, struct mbuf *m, int off, | ||||
| if (rm != NULL && (rm->action == PF_NONAT || | if (rm != NULL && (rm->action == PF_NONAT || | ||||
| rm->action == PF_NORDR || rm->action == PF_NOBINAT)) | rm->action == PF_NORDR || rm->action == PF_NOBINAT)) | ||||
| return (NULL); | return (NULL); | ||||
| return (rm); | return (rm); | ||||
| } | } | ||||
| static int | static int | ||||
| pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r, | pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_krule *r, | ||||
| struct pf_addr *saddr, uint16_t sport, struct pf_addr *daddr, | struct pf_addr *saddr, uint16_t sport, struct pf_addr *daddr, | ||||
| uint16_t dport, struct pf_addr *naddr, uint16_t *nport, uint16_t low, | uint16_t dport, struct pf_addr *naddr, uint16_t *nport, uint16_t low, | ||||
| uint16_t high, struct pf_ksrc_node **sn) | uint16_t high, struct pf_ksrc_node **sn) | ||||
| { | { | ||||
| struct pf_state_key_cmp key; | struct pf_state_key_cmp key; | ||||
| struct pf_addr init_addr; | struct pf_addr init_addr; | ||||
| bzero(&init_addr, sizeof(init_addr)); | bzero(&init_addr, sizeof(init_addr)); | ||||
| ▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | do { | ||||
| default: | default: | ||||
| return (1); | return (1); | ||||
| } | } | ||||
| } while (! PF_AEQ(&init_addr, naddr, af) ); | } while (! PF_AEQ(&init_addr, naddr, af) ); | ||||
| return (1); /* none available */ | return (1); /* none available */ | ||||
| } | } | ||||
| int | int | ||||
| pf_map_addr(sa_family_t af, struct pf_rule *r, struct pf_addr *saddr, | pf_map_addr(sa_family_t af, struct pf_krule *r, struct pf_addr *saddr, | ||||
| struct pf_addr *naddr, struct pf_addr *init_addr, struct pf_ksrc_node **sn) | struct pf_addr *naddr, struct pf_addr *init_addr, struct pf_ksrc_node **sn) | ||||
| { | { | ||||
| struct pf_pool *rpool = &r->rpool; | struct pf_pool *rpool = &r->rpool; | ||||
| struct pf_addr *raddr = NULL, *rmask = NULL; | struct pf_addr *raddr = NULL, *rmask = NULL; | ||||
| /* Try to find a src_node if none was given and this | /* Try to find a src_node if none was given and this | ||||
| is a sticky-address rule. */ | is a sticky-address rule. */ | ||||
| if (*sn == NULL && r->rpool.opts & PF_POOL_STICKYADDR && | if (*sn == NULL && r->rpool.opts & PF_POOL_STICKYADDR && | ||||
| ▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | if (V_pf_status.debug >= PF_DEBUG_MISC && | ||||
| printf("pf_map_addr: selected address "); | printf("pf_map_addr: selected address "); | ||||
| pf_print_host(naddr, 0, af); | pf_print_host(naddr, 0, af); | ||||
| printf("\n"); | printf("\n"); | ||||
| } | } | ||||
| return (0); | return (0); | ||||
| } | } | ||||
| struct pf_rule * | struct pf_krule * | ||||
| pf_get_translation(struct pf_pdesc *pd, struct mbuf *m, int off, int direction, | pf_get_translation(struct pf_pdesc *pd, struct mbuf *m, int off, int direction, | ||||
| struct pfi_kif *kif, struct pf_ksrc_node **sn, | struct pfi_kif *kif, struct pf_ksrc_node **sn, | ||||
| struct pf_state_key **skp, struct pf_state_key **nkp, | struct pf_state_key **skp, struct pf_state_key **nkp, | ||||
| struct pf_addr *saddr, struct pf_addr *daddr, | struct pf_addr *saddr, struct pf_addr *daddr, | ||||
| uint16_t sport, uint16_t dport, struct pf_anchor_stackframe *anchor_stack) | uint16_t sport, uint16_t dport, struct pf_kanchor_stackframe *anchor_stack) | ||||
| { | { | ||||
| struct pf_rule *r = NULL; | struct pf_krule *r = NULL; | ||||
| struct pf_addr *naddr; | struct pf_addr *naddr; | ||||
| uint16_t *nport; | uint16_t *nport; | ||||
| PF_RULES_RASSERT(); | PF_RULES_RASSERT(); | ||||
| KASSERT(*skp == NULL, ("*skp not NULL")); | KASSERT(*skp == NULL, ("*skp not NULL")); | ||||
| KASSERT(*nkp == NULL, ("*nkp not NULL")); | KASSERT(*nkp == NULL, ("*nkp not NULL")); | ||||
| if (direction == PF_OUT) { | if (direction == PF_OUT) { | ||||
| ▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines | |||||