/* ****************************************************************************** * INTERPEAK SOURCE FILE * * Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipl2tp_v2_pw.c,v $ $Revision: 1.5.16.1 $ * $Source: /home/interpeak/CVSRoot/ipl2tp/src/ipl2tp_v2_pw.c,v $ * $Author: jren $ * $State: Exp $ $Locker: $ * * INTERPEAK_COPYRIGHT_STRING * Design and implementation by Joel Hortelius ****************************************************************************** */ /* **************************************************************************** * 1 DESCRIPTION **************************************************************************** */ /* **************************************************************************** * 2 CONFIGURATION **************************************************************************** */ /* **************************************************************************** * 3 INCLUDE FILES **************************************************************************** */ #include "ipl2tp_h.h" #include "ipl2tp_api.h" #include "ipl2tp_avp.h" #include "ipl2tp_data.h" #include "ipl2tp_message.h" #include "ipl2tp_state.h" #include "ipl2tp_pseudowire.h" #include "ipl2tp_trpt.h" #include "ipl2tp_v2.h" #include "ipl2tp_v2_state.h" #include "ipl2tp_v2_pw.h" /* **************************************************************************** * 4 DEFINES **************************************************************************** */ /* **************************************************************************** * 5 TYPES **************************************************************************** */ /* **************************************************************************** * 6 EXTERN PROTOTYPES **************************************************************************** */ /* **************************************************************************** * 7 LOCAL PROTOTYPES **************************************************************************** */ /* **************************************************************************** * 8 DATA **************************************************************************** */ /* **************************************************************************** * 9 STATIC FUNCTIONS **************************************************************************** */ /* **************************************************************************** * 10 GLOBAL FUNCTIONS **************************************************************************** */ /* *=========================================================================== * ipl2tp_v2_pw_ppp_input *=========================================================================== * Description: Feed an incoming PPP packet to the IPL2TP engine. * Parameters: session - The session which the packet belongs to. * buffer - PPP packet. * length - Length of PPP packet. * offset - Number of bytes before 'buffer' that may be used. * align - Alignment requirement for output buffer. * Returns: IPL2TP_STATUS_OK if success. * IPL2TP_STATUS_BADID if invalid session ID. */ IP_GLOBAL Ipl2tp_status ipl2tp_v2_pw_ppp_input(Ipl2tp_session *session, void *buffer, int length, int offset, int align) { Ipl2tp_tunnel *tunnel = session->tunnel; Ipl2tp_v2_umessage *message; int rhsize = 8; int hsize; Ip_u16 flv; struct Ip_iovec iov[2]; int iov_len = 0; char hdr[32]; /* Sequencing required? */ if (session->v.v2.sequencing != 0) { rhsize += 4; } /* Remember min header size */ hsize = rhsize; /* Check alignment */ #ifdef IPL2TP_V2_STRICT_HEADER_ALIGNMENT if ((((int)buffer - hsize) % align) != 0) { hsize += 2; hsize += (((int)buffer - hsize) % align); } #endif /* Header fits in allocated offset? */ if (hsize > offset) { iov[iov_len].iov_base = hdr; iov[iov_len].iov_len = hsize; iov_len++; iov[iov_len].iov_base = buffer; iov[iov_len].iov_len = length; iov_len++; message = (Ipl2tp_v2_umessage *) hdr; } else { Ip_u8 *frame = buffer; message = (Ipl2tp_v2_umessage *)(frame - hsize); iov[iov_len].iov_base = message; iov[iov_len].iov_len = length + hsize; iov_len++; } /* Enter header fields */ flv = IPL2TP_HEADER_FLAG_LENGTH; flv |= IPL2TP_VERSION_L2TPV2; IP_SET_HTONS(&message->len_seq.length, (hsize + length)); IP_SET_HTONS(&message->len_seq.tunnel_id, ((Ip_u16) (tunnel->remote.key.ident))); IP_SET_HTONS(&message->len_seq.session_id, ((Ip_u16) (session->remote.key.ident))); /* Enter sequence number */ if (session->v.v2.sequencing != 0) { Ip_u16 seq = session->v.v2.ns++; flv |= IPL2TP_HEADER_FLAG_SEQUENCE; IP_SET_HTONS(&message->len_seq.ns, seq); message->len_seq.nr = 0; } #ifdef IPL2TP_V2_STRICT_HEADER_ALIGNMENT /* Enter offset */ if (hsize != rhsize) { flv |= IPL2TP_HEADER_FLAG_OFFSET; if (session->v.v2.sequencing == 0) { IP_SET_HTONS(&message->len_off.offset, hsize - sizeof(message->len_off)); } else { IP_SET_HTONS(&message->len_seq_off.offset, hsize - sizeof(message->len_seq_off)); } } #endif IP_SET_HTONS(&message->len_seq.flv, flv); ipl2tp_trpt_data_output(tunnel, iov, iov_len); return IPL2TP_STATUS_OK; } /* **************************************************************************** * 11 PUBLIC FUNCTIONS **************************************************************************** */ /* **************************************************************************** * END OF FILE **************************************************************************** */