The Assimilation Project
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lldp_min.c File Reference

Implements minimal client-oriented LLDP capabilities. More...

#include <stdio.h>
#include <string.h>
#include <lldp.h>
#include <tlvhelper.h>
Include dependency graph for lldp_min.c:

Go to the source code of this file.

Macros

#define DIMOF(a)   (sizeof(a)/sizeof(a[0]))
 
#define NETTLV_INITPKTOFFSET   14
 
#define NETTLV_HDRSZ   2
 

Functions

guint8 get_lldptlv_type (const void *tlv_vp, const void *pktend)
 Return the 'Type' of the given LLDP TLV entry The Type is the high order 7 bits from the zeroth byte in the TLV entry. More...
 
gsize get_lldptlv_len (const void *tlv_vp, const void *pktend)
 Return the 'Length' of the given LLDP TLV entry. More...
 
const void * get_lldptlv_body (const void *tlv_vp, const void *pktend)
 Return the 'Value' of the given LLDP TLV entry. More...
 
gboolean is_valid_lldp_packet (const void *tlv_vp, const void *pktend)
 
const void * get_lldptlv_first (const void *packet, const void *pktend)
 
const void * get_lldptlv_next (const void *tlv_vp, const void *pktend)
 Return pointer to the next LLDP TLV entry after the current location. More...
 
const void * find_next_lldptlv_type (const void *tlv_vp, unsigned tlvtype, const void *pktend)
 Return pointer to the next LLDP entry of the given type at or after the current location. More...
 
const void * get_lldp_chassis_id (gconstpointer tlv_vp, gssize *idlength, gconstpointer pktend)
 Return a pointer to the chassis id Value entry, and its length. More...
 
const void * get_lldp_port_id (gconstpointer tlv_vp, gssize *idlength, gconstpointer pktend)
 Return a pointer to the port id Value entry, and its length. More...
 

Detailed Description

Implements minimal client-oriented LLDP capabilities.

This file contains the minimal LLDP capability for a client - enough for it to be able to understand and validate a CDP packet's structure, return any particular TLV and specifically to be able to locate the chassis id and port id (which the client needs).

This file is part of the Assimilation Project.

Author
Copyright © 2011, 2012 - Alan Robertson alanr.nosp@m.@uni.nosp@m.x.sh
The Assimilation software is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The Assimilation software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the Assimilation Project software. If not, see http://www.gnu.org/licenses/

Definition in file lldp_min.c.

Macro Definition Documentation

Function Documentation

const void* find_next_lldptlv_type ( const void *  tlv_vp,
unsigned  tlvtype,
const void *  pktend 
)

Return pointer to the next LLDP entry of the given type at or after the current location.

Parameters
[in]tlv_vpPointer to the current TLV
[in]tlvtypeType of TLV we're looking for
[in]pktendPointer to first byte beyond the packet.

Definition at line 208 of file lldp_min.c.

References get_lldptlv_next(), get_lldptlv_type(), and NETTLV_HDRSZ.

Referenced by get_lldp_chassis_id(), and get_lldp_port_id().

Here is the call graph for this function:

Here is the caller graph for this function:

const void* get_lldp_chassis_id ( gconstpointer  tlv_vp,
gssize *  idlength,
gconstpointer  pktend 
)

Return a pointer to the chassis id Value entry, and its length.

Returns
pointer to the chassis ID value, and its length.
Parameters
[in]tlv_vpPointer to beginning of LLDP packet
[out]idlengthLength of the chassis id
[in]pktendPointer to first byte beyond packet.

Definition at line 224 of file lldp_min.c.

References find_next_lldptlv_type(), get_lldptlv_body(), get_lldptlv_first(), get_lldptlv_len(), and LLDP_TLV_CHID.

Here is the call graph for this function:

const void* get_lldp_port_id ( gconstpointer  tlv_vp,
gssize *  idlength,
gconstpointer  pktend 
)

Return a pointer to the port id Value entry, and its length.

Returns
pointer to the port ID value, and its length.
Parameters
[in]tlv_vpPointer to beginning of LLDP packet
[out]idlengthLength of the port id value
[in]pktendPointer to first byte beyond packet.

Definition at line 241 of file lldp_min.c.

References find_next_lldptlv_type(), get_lldptlv_body(), get_lldptlv_first(), get_lldptlv_len(), and LLDP_TLV_PID.

Here is the call graph for this function:

const void* get_lldptlv_body ( const void *  tlv_vp,
const void *  pktend 
)

Return the 'Value' of the given LLDP TLV entry.

Parameters
[in]tlv_vpPointer to beginning of TLV entry,
[in]pktendPointer to one byte past end of packet

Definition at line 106 of file lldp_min.c.

References NETTLV_HDRSZ.

Referenced by cma.AssimCclasses.pySwitchDiscovery::decode_discovery(), dump_lldp_packet(), get_lldp_chassis_id(), get_lldp_port_id(), and is_valid_lldp_packet().

Here is the caller graph for this function:

const void* get_lldptlv_first ( const void *  packet,
const void *  pktend 
)
Parameters
[in]packetPointer to beginning of LLDP packet
[in]pktendPointer to first byte after the end of the LLDP packet

Definition at line 174 of file lldp_min.c.

References get_lldptlv_len(), NETTLV_HDRSZ, and NETTLV_INITPKTOFFSET.

Referenced by cma.AssimCclasses.pySwitchDiscovery::decode_discovery(), dump_lldp_packet(), get_lldp_chassis_id(), get_lldp_port_id(), and is_valid_lldp_packet().

Here is the call graph for this function:

Here is the caller graph for this function:

gsize get_lldptlv_len ( const void *  tlv_vp,
const void *  pktend 
)

Return the 'Length' of the given LLDP TLV entry.

The length is the low order bit from the zeroth byte plus all 8 bits of the second byte

Parameters
[in]tlv_vpPointer to beginning of TLV entry
[in]pktendPointer to one byte past end of packet

Definition at line 93 of file lldp_min.c.

References cma.tests.cma_test::byte1, and tlv_get_guint8().

Referenced by cma.AssimCclasses.pySwitchDiscovery::decode_discovery(), dump_lldp_packet(), get_lldp_chassis_id(), get_lldp_port_id(), get_lldptlv_first(), get_lldptlv_next(), and is_valid_lldp_packet().

Here is the call graph for this function:

Here is the caller graph for this function:

const void* get_lldptlv_next ( const void *  tlv_vp,
const void *  pktend 
)

Return pointer to the next LLDP TLV entry after the current location.

Parameters
[in]tlv_vpPointer to current LLDP TLV entry
[in]pktendPointer to first byte after the end of the LLDP packet

Definition at line 188 of file lldp_min.c.

References get_lldptlv_len(), get_lldptlv_type(), LLDP_TLV_END, and NETTLV_HDRSZ.

Referenced by cma.AssimCclasses.pySwitchDiscovery::decode_discovery(), dump_lldp_packet(), find_next_lldptlv_type(), and is_valid_lldp_packet().

Here is the call graph for this function:

Here is the caller graph for this function:

guint8 get_lldptlv_type ( const void *  tlv_vp,
const void *  pktend 
)

Return the 'Type' of the given LLDP TLV entry The Type is the high order 7 bits from the zeroth byte in the TLV entry.

Parameters
[in]tlv_vpPointer to beginning of TLV entry
[in]pktendPointer to one byte past end of packet

Definition at line 83 of file lldp_min.c.

References tlv_get_guint8().

Referenced by cma.AssimCclasses.pySwitchDiscovery::decode_discovery(), dump_lldp_packet(), find_next_lldptlv_type(), get_lldptlv_next(), and is_valid_lldp_packet().

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean is_valid_lldp_packet ( const void *  tlv_vp,
const void *  pktend 
)
Todo:
validate destination MAC 01:80:c2:00:00:0e and Ethernet protocol 0x88cc. Return TRUE if this is a valid LLDP packet.

Definition at line 116 of file lldp_min.c.

References DIMOF, get_lldptlv_body(), get_lldptlv_first(), get_lldptlv_len(), get_lldptlv_next(), get_lldptlv_type(), LLDP_TLV_CHID, LLDP_TLV_END, LLDP_TLV_PID, LLDP_TLV_TTL, and NETTLV_HDRSZ.

Referenced by cma.AssimCclasses.pySwitchDiscovery::decode_discovery(), and dump_lldp_packet().

Here is the call graph for this function:

Here is the caller graph for this function: