Skip to content

Commit

Permalink
1, add hash target for quic schedule
Browse files Browse the repository at this point in the history
2, fix ipvsadm edit bug when snat is not set
  • Loading branch information
mscbg authored and beacer committed May 11, 2018
1 parent b9555ea commit bd0c2bb
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 34 deletions.
3 changes: 3 additions & 0 deletions include/ipvs/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#define DP_VS_SVC_F_HASHED 0x0002 /* hashed entry */
#define DP_VS_SVC_F_SYNPROXY 0x8000 /* synrpoxy flag */

#define DP_VS_SVC_F_SIP_HASH 0x0100 /* sip hash target */
#define DP_VS_SVC_F_QID_HASH 0x0200 /* quic cid hash target */

#define DP_VS_SCHEDNAME_MAXLEN 16

rte_rwlock_t __dp_vs_svc_lock;
Expand Down
89 changes: 82 additions & 7 deletions src/ipvs/ip_vs_conhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,90 @@

#define REPLICA 160

#define QUIC_PACKET_8BYTE_CONNECTION_ID (1 << 3)


/*session id hash target for quic*/
static int get_quic_hash_target(struct rte_mbuf *mbuf, uint64_t *quic_cid)
{
uint8_t pub_flags;
uint16_t data_off;
char *quic_data;

data_off = mbuf->data_off;

if (unlikely(NULL == rte_pktmbuf_adj(mbuf,
ip4_hdrlen(mbuf) + sizeof(struct udp_hdr)))) {
RTE_LOG(ERR, IPVS, "mbuf len is not enough for udp\n");
return EDPVS_DPDKAPIFAIL;
}

if (unlikely(rte_pktmbuf_data_len(mbuf) <
(sizeof(pub_flags) + sizeof(*quic_cid)))) {
RTE_LOG(ERR, IPVS, "mbuf len is not enough for QUIC\n");
goto no_cid;
}

quic_data = rte_pktmbuf_mtod(mbuf, char *);
pub_flags = *((uint8_t *)quic_data);

if ((pub_flags & QUIC_PACKET_8BYTE_CONNECTION_ID) == 0) {
RTE_LOG(WARNING, IPVS, "packet without cid, pub_flag:%u\n", pub_flags);
goto no_cid;
}

quic_data += sizeof(pub_flags);

*quic_cid = *((uint64_t*)quic_data);

rte_pktmbuf_prepend(mbuf, mbuf->data_off - data_off);

return EDPVS_OK;

no_cid:
rte_pktmbuf_prepend(mbuf, mbuf->data_off - data_off);
return EDPVS_NOTEXIST;
}

/*source ip hash target*/
static int get_sip_hash_target(struct rte_mbuf *mbuf, uint32_t *sip)
{
*sip = ip4_hdr(mbuf)->src_addr;
return EDPVS_OK;
}


static inline struct dp_vs_dest *
dp_vs_conhash_get(int af, struct conhash_s *conhash,
const uint32_t addr)
dp_vs_conhash_get(struct dp_vs_service *svc, struct conhash_s *conhash,
struct rte_mbuf *mbuf)
{
char str[40];
char str[40] = {0};
uint64_t quic_cid;
uint32_t sip;
const struct node_s *node;

snprintf(str, sizeof(str),"%u", rte_be_to_cpu_32(addr));
if (svc->flags & DP_VS_SVC_F_QID_HASH) {
if (EDPVS_OK != get_quic_hash_target(mbuf, &quic_cid)) {
/*may not have cid, hash it by sip*/
if (EDPVS_OK != get_sip_hash_target(mbuf, &sip))
return NULL;
snprintf(str, sizeof(str),"%u", sip);
}
else
snprintf(str, sizeof(str),"%lu", quic_cid);
}

else if (svc->flags & DP_VS_SVC_F_SIP_HASH) {
if (EDPVS_OK != get_sip_hash_target(mbuf, &sip))
return NULL;
snprintf(str, sizeof(str),"%u", sip);
}

else {
RTE_LOG(ERR, IPVS, "%s: invalid hash target.\n", __func__);
return NULL;
}

node = conhash_lookup(conhash, str);
return node == NULL? NULL: node->data;
}
Expand Down Expand Up @@ -57,7 +133,7 @@ dp_vs_conhash_assign(struct dp_vs_service *svc)
rte_atomic32_inc(&dest->refcnt);
p_node->data = dest;

snprintf(str, sizeof(str), "%u", rte_be_to_cpu_32(dest->addr.in.s_addr));
snprintf(str, sizeof(str), "%u", dest->addr.in.s_addr);

conhash_set_node(p_node, str, weight*REPLICA);
conhash_add_node(svc->sched_data, p_node);
Expand Down Expand Up @@ -124,8 +200,7 @@ dp_vs_conhash_schedule(struct dp_vs_service *svc, const struct rte_mbuf *mbuf)
{
struct dp_vs_dest *dest;

dest = dp_vs_conhash_get(svc->af, (struct conhash_s *)(svc->sched_data),
ip4_hdr(mbuf)->src_addr);
dest = dp_vs_conhash_get(svc, (struct conhash_s *)(svc->sched_data), (struct rte_mbuf *)mbuf);

if (!dest
|| !(dest->flags & DPVS_DEST_F_AVAILABLE)
Expand Down
73 changes: 51 additions & 22 deletions tools/ipvsadm/ipvsadm.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ static const char* optnames[] = {
"synproxy" ,
"ifname" ,
"sockpair" ,
"hash-target",
};

/*
Expand All @@ -211,27 +212,27 @@ static const char* optnames[] = {
*/
static const char commands_v_options[NUMBER_OF_CMD][NUMBER_OF_OPT] =
{
/* -n -c svc -s -p -M -r fwd -w -x -y -mc tot dmn -st -rt thr -pc srt sid -ex ops pe laddr blst syn ifname sockpair */
/*ADD*/ {'x', 'x', '+', ' ', ' ', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', ' ', 'x', 'x', 'x', ' ', 'x' ,'x'},
/*EDIT*/ {'x', 'x', '+', ' ', ' ', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', ' ', 'x', 'x', 'x', ' ', 'x' ,'x'},
/*DEL*/ {'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x'},
/*FLUSH*/ {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x'},
/*LIST*/ {' ', '1', '1', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', '1', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'x', 'x', 'x', 'x', 'x', 'x' ,' '},
/*ADDSRV*/ {'x', 'x', '+', 'x', 'x', 'x', '+', ' ', ' ', ' ', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x'},
/*DELSRV*/ {'x', 'x', '+', 'x', 'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x'},
/*EDITSRV*/ {'x', 'x', '+', 'x', 'x', 'x', '+', ' ', ' ', ' ', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x'},
/*TIMEOUT*/ {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x'},
/*STARTD*/ {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x'},
/*STOPD*/ {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x'},
/*RESTORE*/ {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x'},
/*SAVE*/ {' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x'},
/*ZERO*/ {'x', 'x', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x'},
/*ADDLADDR*/ {'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', '+', 'x', 'x', '+' ,'x'},
/*DELLADDR*/ {'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', '+', 'x', 'x', '+' ,'x'},
/*GETLADDR*/ {'x', 'x', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x'},
/*ADDBLKLST*/{'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', '+', 'x', 'x' ,'x'},
/*DELBLKLST*/{'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', '+', 'x', 'x' ,'x'},
/*GETBLKLST*/{'x', 'x', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x'},
/* -n -c svc -s -p -M -r fwd -w -x -y -mc tot dmn -st -rt thr -pc srt sid -ex ops pe laddr blst syn ifname sockpair hashtag*/
/*ADD*/ {'x', 'x', '+', ' ', ' ', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', ' ', 'x', 'x', 'x', ' ', 'x' ,'x' ,' '},
/*EDIT*/ {'x', 'x', '+', ' ', ' ', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', ' ', 'x', 'x', 'x', ' ', 'x' ,'x' ,' '},
/*DEL*/ {'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x' ,'x'},
/*FLUSH*/ {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x' ,'x'},
/*LIST*/ {' ', '1', '1', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', '1', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'x', 'x', 'x', 'x', 'x', 'x' ,' ' ,'x'},
/*ADDSRV*/ {'x', 'x', '+', 'x', 'x', 'x', '+', ' ', ' ', ' ', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x' ,'x'},
/*DELSRV*/ {'x', 'x', '+', 'x', 'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x' ,'x'},
/*EDITSRV*/ {'x', 'x', '+', 'x', 'x', 'x', '+', ' ', ' ', ' ', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x' ,'x'},
/*TIMEOUT*/ {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x' ,'x'},
/*STARTD*/ {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x' ,'x'},
/*STOPD*/ {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x' ,'x'},
/*RESTORE*/ {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x' ,'x'},
/*SAVE*/ {' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x' ,'x'},
/*ZERO*/ {'x', 'x', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x' ,'x'},
/*ADDLADDR*/ {'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', '+', 'x', 'x', '+' ,'x' ,'x'},
/*DELLADDR*/ {'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', '+', 'x', 'x', '+' ,'x' ,'x'},
/*GETLADDR*/ {'x', 'x', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x' ,'x'},
/*ADDBLKLST*/{'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', '+', 'x', 'x' ,'x' ,'x'},
/*DELBLKLST*/{'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', '+', 'x', 'x' ,'x' ,'x'},
/*GETBLKLST*/{'x', 'x', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ,'x' ,'x'},
};

/* printing format flags */
Expand Down Expand Up @@ -450,6 +451,7 @@ parse_options(int argc, char **argv, struct ipvs_command_entry *ce,
{ "synproxy", 'j' , POPT_ARG_STRING, &optarg, 'j', NULL, NULL },
{ "ifname", 'F', POPT_ARG_STRING, &optarg, 'F', NULL, NULL },
{ "match", 'H', POPT_ARG_STRING, &optarg, 'H', NULL, NULL },
{ "hash-target", 'Y', POPT_ARG_STRING, &optarg, 'Y', NULL, NULL },
{ NULL, 0, 0, NULL, 0, NULL, NULL }
};

Expand Down Expand Up @@ -578,6 +580,8 @@ parse_options(int argc, char **argv, struct ipvs_command_entry *ce,
set_option(options, OPT_SCHEDULER);
strncpy(ce->svc.sched_name,
optarg, IP_VS_SCHEDNAME_MAXLEN);
if (!memcmp(ce->svc.sched_name, "conhash", strlen("conhash")))
ce->svc.flags = ce->svc.flags | IP_VS_SVC_F_SIP_HASH;
break;
case 'p':
set_option(options, OPT_PERSISTENT);
Expand Down Expand Up @@ -767,6 +771,26 @@ parse_options(int argc, char **argv, struct ipvs_command_entry *ce,

break;
}
case 'Y':
{
set_option(options, OPT_HASHTAG);

if (strcmp(ce->svc.sched_name, "conhash"))
fail(2 , "hash target can only be set when schedule is conhash\n");
if (!memcmp(optarg, "sip", strlen("sip"))) {
set_option(options, OPT_SIPHASH);
ce->svc.flags = ce->svc.flags | IP_VS_SVC_F_SIP_HASH;
ce->svc.flags = ce->svc.flags & (~IP_VS_SVC_F_QID_HASH);
}
else if (!memcmp(optarg, "qid", strlen("qid"))) {
set_option(options, OPT_QIDHASH);
ce->svc.flags = ce->svc.flags | IP_VS_SVC_F_QID_HASH;
ce->svc.flags = ce->svc.flags & (~IP_VS_SVC_F_SIP_HASH);
}
else
fail(2 , "hash target not support\n");
break;
}
default:
fail(2, "invalid option `%s'",
poptBadOption(context, POPT_BADOPTION_NOALIAS));
Expand Down Expand Up @@ -1429,7 +1453,8 @@ static void usage_exit(const char *program, const int exit_status)
" --numeric -n numeric output of addresses and ports\n"
" --ifname -F nic interface for laddrs\n"
" --synproxy -j TCP syn proxy\n"
" --match -H MATCH select service by MATCH 'proto,srange,drange,iif,oif'\n",
" --match -H MATCH select service by MATCH 'proto,srange,drange,iif,oif'\n"
" --hash-target -Y hashtag choose target for conhash (support sip or qid for quic)\n",
DEF_SCHED);

exit(exit_status);
Expand Down Expand Up @@ -1809,6 +1834,10 @@ print_service_entry(ipvs_service_entry_t *se, unsigned int format)
print_largenum(se->stats.outbps, format);
} else {
printf("%s %s", svc_name, se->sched_name);
if (se->flags & IP_VS_SVC_F_SIP_HASH)
printf(" sip");
if (se->flags & IP_VS_SVC_F_QID_HASH)
printf(" qid");
if (se->flags & IP_VS_SVC_F_PERSISTENT) {
printf(" persistent %u", se->timeout);
if (se->af == AF_INET)
Expand Down
14 changes: 14 additions & 0 deletions tools/keepalived/keepalived/check/check_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,19 @@ dump_vs(void *data)
#endif
}

switch (vs->hash_target) {

case IP_VS_SVC_F_SIP_HASH:
log_message(LOG_INFO, " hash target = sip");
break;
case IP_VS_SVC_F_QID_HASH:
log_message(LOG_INFO, " hash target = quicid");
break;
default:
log_message(LOG_INFO, " hash target not support");
break;
}

if (vs->s_svr) {
log_message(LOG_INFO, " sorry server = %s"
, FMT_RS(vs->s_svr));
Expand Down Expand Up @@ -428,6 +441,7 @@ alloc_vs(char *ip, char *port)
new->local_addr_gname = NULL;
new->blklst_addr_gname = NULL;
new->vip_bind_dev = NULL;
new->hash_target = 0;
memset(new->srange, 0, 256);
memset(new->drange, 0, 256);
memset(new->iifname, 0, IFNAMSIZ);
Expand Down
18 changes: 18 additions & 0 deletions tools/keepalived/keepalived/check/check_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,23 @@ iif_handler(vector_t *strvec)
snprintf(vs->oifname, sizeof(vs->oifname), "%s", (char *)vector_slot(strvec, 1));
}

static void
hash_target_handler(vector_t *strvec)
{
virtual_server_t *vs = LIST_TAIL_DATA(check_data->vs);
char *str = vector_slot(strvec, 1);

if (!strcmp(str, "sip"))
vs->hash_target = IP_VS_SVC_F_SIP_HASH;
else if (!strcmp(str, "qid"))
vs->hash_target = IP_VS_SVC_F_QID_HASH;
else {
vs->hash_target = IP_VS_SVC_F_SIP_HASH;
log_message(LOG_INFO, "PARSER : unknown [%s] hash target, use source_ip", str);
}
}


vector_t *
check_init_keywords(void)
{
Expand Down Expand Up @@ -440,6 +457,7 @@ check_init_keywords(void)
install_keyword("dst-range", &dst_range_handler);
install_keyword("oif", &oif_handler);
install_keyword("iif", &iif_handler);
install_keyword("hash_target", &hash_target_handler);

/* Pool regression detection and handling. */
install_keyword("alpha", &alpha_handler);
Expand Down
9 changes: 8 additions & 1 deletion tools/keepalived/keepalived/check/ipvswrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,16 @@ ipvs_set_rule(int cmd, virtual_server_t * vs, real_server_t * rs)
if (vs->granularity_persistence)
srule->netmask = vs->granularity_persistence;

if(vs->syn_proxy)
if (vs->syn_proxy)
srule->flags |= IP_VS_CONN_F_SYNPROXY;

if (!strcmp(vs->sched, "conhash")) {
if (vs->hash_target)
srule->flags |= vs->hash_target;
else
srule->flags |= IP_VS_SVC_F_SIP_HASH; //default
}

/* SVR specific */
if (rs) {
if (cmd == IP_VS_SO_SET_ADDDEST || cmd == IP_VS_SO_SET_DELDEST ||
Expand Down
2 changes: 2 additions & 0 deletions tools/keepalived/keepalived/include/check_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ typedef struct _virtual_server {
char drange[256];
char iifname[IFNAMSIZ];
char oifname[IFNAMSIZ];
unsigned hash_target;
#if defined(_WITH_SNMP_) && defined(_KRNL_2_6_) && defined(_WITH_LVS_)
/* Statistics */
time_t lastupdated;
Expand Down Expand Up @@ -258,6 +259,7 @@ static inline int inaddr_equal(sa_family_t family, void *addr1, void *addr2)
(X)->vfwmark == (Y)->vfwmark &&\
(X)->service_type == (Y)->service_type &&\
(X)->loadbalancing_kind == (Y)->loadbalancing_kind &&\
(X)->hash_target == (Y)->hash_target &&\
(X)->nat_mask == (Y)->nat_mask &&\
(X)->granularity_persistence == (Y)->granularity_persistence &&\
(X)->syn_proxy == (Y)->syn_proxy &&\
Expand Down
3 changes: 3 additions & 0 deletions tools/keepalived/keepalived/libipvs-2.6/ip_vs.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
#define IP_VS_SVC_F_SCHED2 0x0010 /* scheduler flag 2 */
#define IP_VS_SVC_F_SCHED3 0x0020 /* scheduler flag 3 */

#define IP_VS_SVC_F_SIP_HASH 0x0100 /* sip hash target */
#define IP_VS_SVC_F_QID_HASH 0x0200 /* quic cid hash target */

#define IP_VS_SVC_F_SCHED_SH_FALLBACK IP_VS_SVC_F_SCHED1 /* SH fallback */
#define IP_VS_SVC_F_SCHED_SH_PORT IP_VS_SVC_F_SCHED2 /* SH use port */

Expand Down
21 changes: 21 additions & 0 deletions tools/keepalived/keepalived/libipvs-2.6/libipvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ int ipvs_update_service_by_options(ipvs_service_t *svc, unsigned int options)

if( options & OPT_SCHEDULER ) {
strcpy(user.sched_name, svc->sched_name);
if (strcmp(svc->sched_name, "conhash")) {
user.flags &= ~IP_VS_SVC_F_QID_HASH;
user.flags &= ~IP_VS_SVC_F_SIP_HASH;
}
else {
user.flags |= IP_VS_SVC_F_SIP_HASH;
}
}

if( options & OPT_PERSISTENT ) {
Expand All @@ -160,6 +167,16 @@ int ipvs_update_service_by_options(ipvs_service_t *svc, unsigned int options)
user.flags |= IP_VS_SVC_F_ONEPACKET;
}

if( options & OPT_SIPHASH ) {
user.flags |= IP_VS_SVC_F_SIP_HASH;
user.flags &= ~IP_VS_SVC_F_QID_HASH;
}

if( options & OPT_QIDHASH ) {
user.flags |= IP_VS_SVC_F_QID_HASH;
user.flags &= ~IP_VS_SVC_F_SIP_HASH;
}

return ipvs_update_service(&user);
}

Expand Down Expand Up @@ -867,5 +884,9 @@ void ipvs_service_entry_2_user(const ipvs_service_entry_t *entry, ipvs_service_t
user->af = entry->af;
user->addr = entry->addr;
strcpy(user->pe_name, entry->pe_name);
strcpy(user->srange, entry->srange);
strcpy(user->drange, entry->drange);
strcpy(user->iifname, entry->iifname);
strcpy(user->iifname, entry->iifname);
}

Loading

0 comments on commit bd0c2bb

Please sign in to comment.