Skip to content

Instantly share code, notes, and snippets.

@kkumar-fk
Last active July 24, 2019 03:03
Show Gist options
  • Save kkumar-fk/b19ac21e4ceed37046dc1c88a7cdcf63 to your computer and use it in GitHub Desktop.
Save kkumar-fk/b19ac21e4ceed37046dc1c88a7cdcf63 to your computer and use it in GitHub Desktop.
code blob
struct sock *reuseport_select_sock(struct sock *sk, unsigned int phash)
{
/* Get control block of sockets in this SO_REUSEPORT group */
struct sock_reuseport *reuse = sk->sk_reuseport_cb;
/* Get count of sockets in the group */
int num_socks = reuse->num_socks;
/* Calculate value between 0 and 'num_socks-1' (both inclusive) */
unsigned int index = reciprocal_scale(phash, num_socks);
/* Index into the SO_REUSEPORT group using this index, and return that socket */
return reuse->socks[index];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment