linux/net/netfilter/ipvs/ip_vs_sh.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * IPVS:        Source Hashing scheduling module
 *
 * Authors:     Wensong Zhang <[email protected]>
 *
 * Changes:
 */

/*
 * The sh algorithm is to select server by the hash key of source IP
 * address. The pseudo code is as follows:
 *
 *       n <- servernode[src_ip];
 *       if (n is dead) OR
 *          (n is overloaded) or (n.weight <= 0) then
 *                 return NULL;
 *
 *       return n;
 *
 * Notes that servernode is a 256-bucket hash table that maps the hash
 * index derived from packet source IP address to the current server
 * array. If the sh scheduler is used in cache cluster, it is good to
 * combine it with cache_bypass feature. When the statically assigned
 * server is dead or overloaded, the load balancer can bypass the cache
 * server and send requests to the original server directly.
 *
 * The weight destination attribute can be used to control the
 * distribution of connections to the destinations in servernode. The
 * greater the weight, the more connections the destination
 * will receive.
 *
 */

#define KMSG_COMPONENT
#define pr_fmt(fmt)

#include <linux/ip.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>

#include <net/ip_vs.h>

#include <net/tcp.h>
#include <linux/udp.h>
#include <linux/sctp.h>


/*
 *      IPVS SH bucket
 */
struct ip_vs_sh_bucket {};

/*
 *     for IPVS SH entry hash table
 */
#ifndef CONFIG_IP_VS_SH_TAB_BITS
#define CONFIG_IP_VS_SH_TAB_BITS
#endif
#define IP_VS_SH_TAB_BITS
#define IP_VS_SH_TAB_SIZE
#define IP_VS_SH_TAB_MASK

struct ip_vs_sh_state {};

/* Helper function to determine if server is unavailable */
static inline bool is_unavailable(struct ip_vs_dest *dest)
{}

/*
 *	Returns hash value for IPVS SH entry
 */
static inline unsigned int
ip_vs_sh_hashkey(int af, const union nf_inet_addr *addr,
		 __be16 port, unsigned int offset)
{}


/*
 *      Get ip_vs_dest associated with supplied parameters.
 */
static inline struct ip_vs_dest *
ip_vs_sh_get(struct ip_vs_service *svc, struct ip_vs_sh_state *s,
	     const union nf_inet_addr *addr, __be16 port)
{}


/* As ip_vs_sh_get, but with fallback if selected server is unavailable
 *
 * The fallback strategy loops around the table starting from a "random"
 * point (in fact, it is chosen to be the original hash value to make the
 * algorithm deterministic) to find a new server.
 */
static inline struct ip_vs_dest *
ip_vs_sh_get_fallback(struct ip_vs_service *svc, struct ip_vs_sh_state *s,
		      const union nf_inet_addr *addr, __be16 port)
{}

/*
 *      Assign all the hash buckets of the specified table with the service.
 */
static int
ip_vs_sh_reassign(struct ip_vs_sh_state *s, struct ip_vs_service *svc)
{}


/*
 *      Flush all the hash buckets of the specified table.
 */
static void ip_vs_sh_flush(struct ip_vs_sh_state *s)
{}


static int ip_vs_sh_init_svc(struct ip_vs_service *svc)
{}


static void ip_vs_sh_done_svc(struct ip_vs_service *svc)
{}


static int ip_vs_sh_dest_changed(struct ip_vs_service *svc,
				 struct ip_vs_dest *dest)
{}


/* Helper function to get port number */
static inline __be16
ip_vs_sh_get_port(const struct sk_buff *skb, struct ip_vs_iphdr *iph)
{}


/*
 *      Source Hashing scheduling
 */
static struct ip_vs_dest *
ip_vs_sh_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
		  struct ip_vs_iphdr *iph)
{}


/*
 *      IPVS SH Scheduler structure
 */
static struct ip_vs_scheduler ip_vs_sh_scheduler =;


static int __init ip_vs_sh_init(void)
{}


static void __exit ip_vs_sh_cleanup(void)
{}


module_init();
module_exit(ip_vs_sh_cleanup);
MODULE_LICENSE();
MODULE_DESCRIPTION();