summaryrefslogtreecommitdiffstats
path: root/extras/vcl-ldpreload
AgeCommit message (Expand)AuthorFilesLines
2020-04-03misc: fix sonarcloud html issueDave Wallace1-1/+1
2018-10-01Fix the path error inside vcl socket_test.shYalei Wang1-2/+2
2018-09-12Always use 'lib' instead of 'lib64'Damjan Marion4-5/+5
2018-01-24docs: Clean up TOCDave Wallace1-1/+1
2017-11-11VCL: clean up disconnect_session debug output.Dave Wallace1-31/+36
2017-10-24VCL-LDPRELOAD: statically link vppcom into libvcl-ldpreload.soDave Wallace17-9269/+25
2017-10-20VCL-LDPRELOAD: Refactor vcom_socket* and fix crash in vppcom_selectDave Wallace2-89/+92
2017-10-19LD_PRELOAD poll implementationshrinivasan ganapathy7-4/+748
2017-10-19vcl-ldpreload: test script enhancementsDave Wallace4-0/+59
2017-10-19VCL-LDPRELOAD: fix iperf3 socket_test.shDave Wallace1-15/+0
2017-10-17VCL_LDPRELOAD: Add unit test scripts.Dave Wallace5-0/+160
2017-10-17VCL: refactor VCL_LDPRELOAD env vars.Dave Wallace1-5/+3
2017-10-16LDPRELOAD: Remove hack code in getpeernameSteven1-14/+0
2017-10-15VCL/LDPRELOAD: getpeername and getsocknameSteven1-30/+10
2017-10-13LDPRELOAD: Add TCP_KEEPIDLE, TCP_KEEPINTVL, and SO_KEEPALIVESteven1-9/+32
2017-10-13LDPRELOAD: Add ioctl, fcntl, and setsockopt supportSteven6-32/+255
2017-10-12Initial push of vcl-ldpreload to extrasKeith Burns (alagalah)14-0/+8327
* Name.Property */ .highlight .nt { color: #f92672 } /* Name.Tag */ .highlight .nv { color: #f8f8f2 } /* Name.Variable */ .highlight .ow { color: #f92672 } /* Operator.Word */ .highlight .w { color: #f8f8f2 } /* Text.Whitespace */ .highlight .mb { color: #ae81ff } /* Literal.Number.Bin */ .highlight .mf { color: #ae81ff } /* Literal.Number.Float */ .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */ .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */ .highlight .mo { color: #ae81ff } /* Literal.Number.Oct */ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ .highlight .sc { color: #e6db74 } /* Literal.String.Char */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef __included_lacp_node_h__
#define __included_lacp_node_h__

#include <vlib/vlib.h>
#include <vlib/unix/unix.h>
#include <vppinfra/format.h>
#include <vppinfra/hash.h>
#include <lacp/protocol.h>
#include <lacp/rx_machine.h>
#include <lacp/tx_machine.h>
#include <lacp/mux_machine.h>
#include <lacp/ptx_machine.h>

typedef enum
{
  LACP_PACKET_TEMPLATE_ETHERNET,
  LACP_N_PACKET_TEMPLATES,
} lacp_packet_template_id_t;

typedef enum
{
  MARKER_PACKET_TEMPLATE_ETHERNET,
  MARKER_N_PACKET_TEMPLATES,
} marker_packet_template_id_t;

typedef enum
{
  LACP_PROCESS_EVENT_START = 1,
  LACP_PROCESS_EVENT_STOP = 2,
} lacp_process_event_t;

#define LACP_DBG(n, args...)			\
  {						\
    lacp_main_t *_lm = &lacp_main;              \
    if (_lm->debug || n->debug)			\
      clib_warning (args);			\
  }

#define LACP_DBG2(n, e, s, m, t)   		  \
  {						  \
    lacp_main_t *_lm = &lacp_main;                \
    if ((m)->debug && (_lm->debug || (n)->debug)) \
      (*m->debug)(n, e, s, t);			  \
  }

/* Packet counters */
#define foreach_lacp_error                                                    \
  _ (NONE, "good lacp packets -- consumed")                                   \
  _ (CACHE_HIT, "good lacp packets -- cache hit")                             \
  _ (UNSUPPORTED, "unsupported slow protocol packets")                        \
  _ (TOO_SMALL, "bad lacp packets -- packet too small")                       \
  _ (BAD_TLV, "bad lacp packets -- bad TLV length")                           \
  _ (BAD_KEY, "Bad key")                                                      \
  _ (LOOPBACK_PORT, "loopback port")                                          \
  _ (DISABLED, "lacp packets received on disabled interfaces")

typedef enum
{
#define _(sym,str) LACP_ERROR_##sym,
  foreach_lacp_error
#undef _
    LACP_N_ERROR,
} lacp_error_t;

#define SECS_IN_A_DAY 86400.0

/* lacp packet trace capture */
typedef struct
{
  u32 sw_if_index;
  u32 len;
  union
  {
    marker_pdu_t marker;
    lacp_pdu_t lacpdu;
  } pkt;
} lacp_input_trace_t;

/** LACP interface details struct */
typedef struct
{
  u32 sw_if_index;
  u8 interface_name[64];
  u32 rx_state;
  u32 tx_state;
  u32 mux_state;
  u32 ptx_state;
  u8 bond_interface_name[64];
  u16 actor_system_priority;
  u8 actor_system[6];
  u16 actor_key;
  u16 actor_port_priority;
  u16 actor_port_number;
  u8 actor_state;
  u16 partner_system_priority;
  u8 partner_system[6];
  u16 partner_key;
  u16 partner_port_priority;
  u16 partner_port_number;
  u8 partner_state;
} lacp_interface_details_t;

typedef struct
{
  /** API message ID base */
  u16 msg_id_base;

  /* convenience variables */
  vlib_main_t *vlib_main;
  vnet_main_t *vnet_main;

  /* Background process node index */
  u32 lacp_process_node_index;

  /* Packet templates for different encap types */
  vlib_packet_template_t packet_templates[LACP_N_PACKET_TEMPLATES];

  /* Packet templates for different encap types */
  vlib_packet_template_t marker_packet_templates[MARKER_N_PACKET_TEMPLATES];

  /* LACP interface count */
  volatile u32 lacp_int;

  /* debug is on or off */
  u8 debug;
} lacp_main_t;

extern lacp_state_struct lacp_state_array[];
extern lacp_main_t lacp_main;

void lacp_create_periodic_process (void);
clib_error_t *lacp_plugin_api_hookup (vlib_main_t * vm);
int lacp_dump_ifs (lacp_interface_details_t ** out_bondids);
lacp_error_t lacp_input (vlib_main_t * vm, vlib_buffer_t * b0, u32 bi0);
void lacp_periodic (vlib_main_t * vm);
u8 *lacp_input_format_trace (u8 * s, va_list * args);
void lacp_init_neighbor (member_if_t * mif, u8 * hw_address,
			 u16 port_number, u32 group);
void lacp_init_state_machines (vlib_main_t * vm, member_if_t * mif);
void lacp_init_rx_machine (vlib_main_t * vm, member_if_t * mif);
void lacp_init_tx_machine (vlib_main_t * vm, member_if_t * mif);
void lacp_init_ptx_machine (vlib_main_t * vm, member_if_t * mif);
void lacp_init_mux_machine (vlib_main_t * vm, member_if_t * mif);
int lacp_selection_logic (vlib_main_t *vm, member_if_t *mif);
void lacp_send_lacp_pdu (vlib_main_t * vm, member_if_t * mif);

static inline void
lacp_stop_timer (f64 * timer)
{
  *timer = 0.0;
}

static inline u8
lacp_timer_is_running (f64 timer)
{
  return (timer != 0.0);
}

static inline u8
lacp_timer_is_expired (vlib_main_t * vm, f64 timer)
{
  f64 now = vlib_time_now (vm);

  return (now >= timer);
}

static inline u8 *
format_rx_sm_state (u8 * s, va_list * args)
{
  lacp_state_struct lacp_rx_sm_state_array[] = {
#define _(b, s, n) {.bit = b, .str = #s, },
    foreach_lacp_rx_sm_state
#undef _
    {.str = NULL}
  };
  int state = va_arg (*args, int);
  lacp_state_struct *state_entry = lacp_rx_sm_state_array;

  if (state >= (sizeof (lacp_rx_sm_state_array) / sizeof (*state_entry)))
    s = format (s, "Bad state %d", state);
  else
    s = format (s, "%s", state_entry[state].str);

  return s;
}

static inline u8 *
format_tx_sm_state (u8 * s, va_list * args)
{
  lacp_state_struct lacp_tx_sm_state_array[] = {
#define _(b, s, n) {.bit = b, .str = #s, },
    foreach_lacp_tx_sm_state
#undef _
    {.str = NULL}
  };
  int state = va_arg (*args, int);
  lacp_state_struct *state_entry = lacp_tx_sm_state_array;

  if (state >= (sizeof (lacp_tx_sm_state_array) / sizeof (*state_entry)))
    s = format (s, "Bad state %d", state);
  else
    s = format (s, "%s", state_entry[state].str);

  return s;
}

static inline u8 *
format_mux_sm_state (u8 * s, va_list * args)
{
  lacp_state_struct lacp_mux_sm_state_array[] = {
#define _(b, s, n) {.bit = b, .str = #s, },
    foreach_lacp_mux_sm_state
#undef _
    {.str = NULL}
  };
  int state = va_arg (*args, int);
  lacp_state_struct *state_entry = lacp_mux_sm_state_array;

  if (state >= (sizeof (lacp_mux_sm_state_array) / sizeof (*state_entry)))
    s = format (s, "Bad state %d", state);
  else
    s = format (s, "%s", state_entry[state].str);

  return s;
}

static inline u8 *
format_ptx_sm_state (u8 * s, va_list * args)
{
  lacp_state_struct lacp_ptx_sm_state_array[] = {
#define _(b, s, n) {.bit = b, .str = #s, },
    foreach_lacp_ptx_sm_state
#undef _
    {.str = NULL}
  };
  int state = va_arg (*args, int);
  lacp_state_struct *state_entry = lacp_ptx_sm_state_array;

  if (state >= (sizeof (lacp_ptx_sm_state_array) / sizeof (*state_entry)))
    s = format (s, "Bad state %d", state);
  else
    s = format (s, "%s", state_entry[state].str);

  return s;
}

static inline int
lacp_bit_test (u8 val, u8 bit)
{
  if (val & (1 << bit))
    return 1;
  else
    return 0;
}

#endif /* __included_lacp_node_h__ */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */