Print this page
WIP to help bringup NAT flows


  34  *
  35  * NOTE:  All reference counts *include* table/tree/list/whatever internment.
  36  * Once an entry is removed, *_REFRELE() must be invoked, and it may or may
  37  * not free something.
  38  */
  39 
  40 #ifdef __cplusplus
  41 extern "C" {
  42 #endif
  43 
  44 /*
  45  * NAT RULES.  Instantiated per-vnet, write-once/read-only entries,
  46  * linkage/entries protected by "rule lock" outside this structure.
  47  */
  48 typedef struct vxlnat_rule_s {
  49         list_node_t vxnr_link;
  50         /* refheld link, or if NULL, this rule is "condemned" and no good. */
  51         struct vxlnat_vnet_s *vxnr_vnet;
  52         in6_addr_t vxnr_myaddr;
  53         in6_addr_t vxnr_pubaddr;

  54         uint8_t vxnr_myether[ETHERADDRL];
  55         uint16_t vxnr_vlanid;   /* Fabrics use this too. */
  56         uint32_t vxnr_refcount;
  57         uint8_t vxnr_prefix;
  58 } vxlnat_rule_t;
  59 #define VXNR_REFHOLD(vxnr) {                    \
  60         atomic_inc_32(&(vxnr)->vxnr_refcount);   \
  61         ASSERT((vxnr)->vxnr_refcount > 0);        \
  62 }
  63 #define VXNR_REFRELE(vxnr) {                                    \
  64         ASSERT((vxnr)->vxnr_refcount > 0);                        \
  65         membar_exit();                                          \
  66         if (atomic_dec_32_nv(&(vxnr)->vxnr_refcount) == 0)       \
  67                 vxlnat_rule_free(vxnr);                         \
  68 }
  69 extern void vxlnat_rule_free(vxlnat_rule_t *);
  70 
  71 /*
  72  * NAT FLOWS.  These are per-vnet, and keyed/searched by:
  73  * <inner-IP-source,IP-dest,inner-source-port,dest-port,protocol>.
  74  * They will be tied-to/part-of
  75  */
  76 typedef struct vxlnat_flow_s {
  77         avl_node_t vxnfl_treenode;
  78         /*
  79          * I'm guessing that dst varies more than src.  Also
  80          * the plan is for the comparitor function to bcmp() both
  81          * of these as one call for IPv6 (if we ever get to that..).
  82          */
  83         in6_addr_t vxnfl_dst;
  84         in6_addr_t vxnfl_src;   /* INNER source address. */
  85         uint32_t vxnfl_ports;
  86         uint8_t vxnfl_protocol;
  87         uint8_t vxnfl_isv4 : 1, /* Will save us 12 bytes of compares... */
  88                 vxlfl_reserved1 : 7;


  89         conn_t *vxnfl_connp;    /* Question - embed instead? */
  90         vxlnat_rule_t *vxnfl_rule; /* Refhold to rule that generated me. */




  91 } vxlnat_flow_t;
  92 /* Exploit endianisms, maintain network order... */
  93 #ifdef _BIG_ENDIAN
  94 #define VXNFL_SPORT(ports) (uint16_t)((ports) >> 16) /* Unsigned all around. */
  95 #define VXNFL_DPORT(ports) ((ports) & 0xFFFF)
  96 #else
  97 #define VXNFL_SPORT(ports) ((ports) & 0xFFFF)
  98 #define VXNFL_DPORT(ports) (uint16_t)((ports) >> 16) /* Unsigned all around. */
  99 #endif











 100 
 101 /*
 102  * 1-1 IP mapping.
 103  */
 104 typedef struct vxlnat_fixed_s {
 105         avl_node_t vxnf_treenode;
 106         in6_addr_t vxnf_addr;   /* For now it needn't match to a rule. */
 107         in6_addr_t vxnf_pubaddr; /* External IP. */
 108         struct vxlnat_vnet_s *vxnf_vnet;
 109         ire_t *vxnf_ire;        /* Should be an IRE_LOCAL from the ftable. */
 110         struct vxlnat_remote_s *vxnf_remote;
 111         uint8_t vxnf_myether[ETHERADDRL];
 112         uint16_t vxnf_vlanid;   /* Stored in network order for quick xmit. */
 113         uint32_t vxnf_refcount;
 114         boolean_t vxnf_clear_router;    /* XXX KEBE SAYS CHEESY HACK */
 115 } vxlnat_fixed_t;
 116 #define VXNF_REFHOLD(vxnf) {                    \
 117         atomic_inc_32(&(vxnf)->vxnf_refcount);   \
 118         ASSERT((vxnf)->vxnf_refcount > 0);        \
 119 }


 246 extern void vxlnat_state_init(void);
 247 extern void vxlnat_state_fini(void);
 248 
 249 extern void vxlnat_public_init(void);
 250 extern void vxlnat_public_fini(void);
 251 extern boolean_t vxlnat_public_hold(in6_addr_t *, boolean_t);
 252 extern void vxlnat_public_rele(in6_addr_t *);
 253 
 254 extern int vxlnat_tree_plus_in6_cmp(const void *, const void *);
 255 
 256 /* ire_recvfn & ire_sendfn functions for 1-1/fixed maps. */
 257 extern void vxlnat_fixed_ire_recv_v4(ire_t *, mblk_t *, void *,
 258     ip_recv_attr_t *);
 259 extern void vxlnat_fixed_ire_recv_v6(ire_t *, mblk_t *, void *,
 260     ip_recv_attr_t *);
 261 extern int vxlnat_fixed_ire_send_v4(ire_t *, mblk_t *, void *,
 262     ip_xmit_attr_t *, uint32_t *);
 263 extern int vxlnat_fixed_ire_send_v6(ire_t *, mblk_t *, void *,
 264     ip_xmit_attr_t *, uint32_t *);
 265 





 266 
 267 extern vxlnat_vnet_t *vxlnat_get_vnet(uint32_t, boolean_t);
 268 
 269 #ifdef __cplusplus
 270 }
 271 #endif
 272 
 273 #endif /* _INET_VXLNAT_IMPL_H */


  34  *
  35  * NOTE:  All reference counts *include* table/tree/list/whatever internment.
  36  * Once an entry is removed, *_REFRELE() must be invoked, and it may or may
  37  * not free something.
  38  */
  39 
  40 #ifdef __cplusplus
  41 extern "C" {
  42 #endif
  43 
  44 /*
  45  * NAT RULES.  Instantiated per-vnet, write-once/read-only entries,
  46  * linkage/entries protected by "rule lock" outside this structure.
  47  */
  48 typedef struct vxlnat_rule_s {
  49         list_node_t vxnr_link;
  50         /* refheld link, or if NULL, this rule is "condemned" and no good. */
  51         struct vxlnat_vnet_s *vxnr_vnet;
  52         in6_addr_t vxnr_myaddr;
  53         in6_addr_t vxnr_pubaddr;
  54         /* XXX KEBE ASKS, ire? */
  55         uint8_t vxnr_myether[ETHERADDRL];
  56         uint16_t vxnr_vlanid;   /* Fabrics use this too. */
  57         uint32_t vxnr_refcount;
  58         uint8_t vxnr_prefix;
  59 } vxlnat_rule_t;
  60 #define VXNR_REFHOLD(vxnr) {                    \
  61         atomic_inc_32(&(vxnr)->vxnr_refcount);   \
  62         ASSERT((vxnr)->vxnr_refcount > 0);        \
  63 }
  64 #define VXNR_REFRELE(vxnr) {                                    \
  65         ASSERT((vxnr)->vxnr_refcount > 0);                        \
  66         membar_exit();                                          \
  67         if (atomic_dec_32_nv(&(vxnr)->vxnr_refcount) == 0)       \
  68                 vxlnat_rule_free(vxnr);                         \
  69 }
  70 extern void vxlnat_rule_free(vxlnat_rule_t *);
  71 
  72 /*
  73  * NAT FLOWS.  These are per-vnet, and keyed/searched by:
  74  * <inner-IP-source,IP-dest,inner-source-port,dest-port,protocol>.
  75  * They will be tied-to/part-of a conn_t.
  76  */
  77 typedef struct vxlnat_flow_s {
  78         avl_node_t vxnfl_treenode;
  79         /*
  80          * I'm guessing that dst varies more than src.  Also
  81          * the plan is for the comparitor function to bcmp() both
  82          * of these as one call for IPv6 (if we ever get to that..).
  83          */
  84         in6_addr_t vxnfl_dst;
  85         in6_addr_t vxnfl_src;   /* INNER source address. */
  86         uint32_t vxnfl_ports;
  87         uint8_t vxnfl_protocol;
  88         uint8_t vxnfl_isv4 : 1, /* Will save us 12 bytes of compares... */
  89                 vxlfl_reserved1 : 7;
  90         /* Theoretically 16 bits lies where this comment is. */
  91         uint32_t vxnfl_refcount;
  92         conn_t *vxnfl_connp;    /* Question - embed instead? */
  93         vxlnat_rule_t *vxnfl_rule; /* Refhold to rule that generated me. */
  94         /*
  95          * XXX KEBE SAYS Other NAT-state belongs here too.  Like time-values
  96          * for timeouts, and more!
  97          */
  98 } vxlnat_flow_t;
  99 /* Exploit endianisms, maintain network order... */
 100 #ifdef _BIG_ENDIAN
 101 #define VXNFL_SPORT(ports) (uint16_t)((ports) >> 16) /* Unsigned all around. */
 102 #define VXNFL_DPORT(ports) ((ports) & 0xFFFF)
 103 #else
 104 #define VXNFL_SPORT(ports) ((ports) & 0xFFFF)
 105 #define VXNFL_DPORT(ports) (uint16_t)((ports) >> 16) /* Unsigned all around. */
 106 #endif
 107 #define VXNFL_REFHOLD(vxnfl) {                  \
 108         atomic_inc_32(&(vxnfl)->vxnfl_refcount); \
 109         ASSERT((vxnfl)->vxnfl_refcount > 0);      \
 110 }
 111 #define VXNFL_REFRELE(vxnfl) {                                  \
 112         ASSERT((vxnfl)->vxnfl_refcount > 0);                      \
 113         membar_exit();                                          \
 114         if (atomic_dec_32_nv(&(vxnfl)->vxnfl_refcount) == 0)     \
 115                 vxlnat_flow_free(vxnfl);                        \
 116 }
 117 extern void vxlnat_flow_free(vxlnat_flow_t *);
 118 
 119 /*
 120  * 1-1 IP mapping.
 121  */
 122 typedef struct vxlnat_fixed_s {
 123         avl_node_t vxnf_treenode;
 124         in6_addr_t vxnf_addr;   /* For now it needn't match to a rule. */
 125         in6_addr_t vxnf_pubaddr; /* External IP. */
 126         struct vxlnat_vnet_s *vxnf_vnet;
 127         ire_t *vxnf_ire;        /* Should be an IRE_LOCAL from the ftable. */
 128         struct vxlnat_remote_s *vxnf_remote;
 129         uint8_t vxnf_myether[ETHERADDRL];
 130         uint16_t vxnf_vlanid;   /* Stored in network order for quick xmit. */
 131         uint32_t vxnf_refcount;
 132         boolean_t vxnf_clear_router;    /* XXX KEBE SAYS CHEESY HACK */
 133 } vxlnat_fixed_t;
 134 #define VXNF_REFHOLD(vxnf) {                    \
 135         atomic_inc_32(&(vxnf)->vxnf_refcount);   \
 136         ASSERT((vxnf)->vxnf_refcount > 0);        \
 137 }


 264 extern void vxlnat_state_init(void);
 265 extern void vxlnat_state_fini(void);
 266 
 267 extern void vxlnat_public_init(void);
 268 extern void vxlnat_public_fini(void);
 269 extern boolean_t vxlnat_public_hold(in6_addr_t *, boolean_t);
 270 extern void vxlnat_public_rele(in6_addr_t *);
 271 
 272 extern int vxlnat_tree_plus_in6_cmp(const void *, const void *);
 273 
 274 /* ire_recvfn & ire_sendfn functions for 1-1/fixed maps. */
 275 extern void vxlnat_fixed_ire_recv_v4(ire_t *, mblk_t *, void *,
 276     ip_recv_attr_t *);
 277 extern void vxlnat_fixed_ire_recv_v6(ire_t *, mblk_t *, void *,
 278     ip_recv_attr_t *);
 279 extern int vxlnat_fixed_ire_send_v4(ire_t *, mblk_t *, void *,
 280     ip_xmit_attr_t *, uint32_t *);
 281 extern int vxlnat_fixed_ire_send_v6(ire_t *, mblk_t *, void *,
 282     ip_xmit_attr_t *, uint32_t *);
 283 
 284 extern boolean_t vxlnat_new_conn(vxlnat_flow_t *);
 285 extern void vxlnat_activate_conn(vxlnat_flow_t *);
 286 #ifdef notyet
 287 extern void vxlnat_deactivate_conn(vxlnat_flow_t *);
 288 #endif
 289 
 290 extern vxlnat_vnet_t *vxlnat_get_vnet(uint32_t, boolean_t);
 291 
 292 #ifdef __cplusplus
 293 }
 294 #endif
 295 
 296 #endif /* _INET_VXLNAT_IMPL_H */