1 /* -*- mode: c; c-file-style: "openbsd" -*- */
3 * Copyright (c) 2012 Vincent Bernat <bernat@luffy.cx>
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 * @defgroup liblldpctl liblldpctl: library to interface with lldpd
24 * `liblldpctl` allows any program to query conveniently and modify the behaviour
25 * of a running lldpd daemon.
27 * To use this library, use `pkg-config` to get the appropriate options:
28 * * `pkg-config --libs lldpctl` for `LIBS` or `LDFLAGS`
29 * * `pkg-config --cflags lldpctl` for `CFLAGS`
31 * @warning This library is tightly coupled with lldpd. The library to use
32 * should be the one shipped with lldpd. Clients of the library are then tied
33 * by the classic API/ABI rules and may be compiled separately.
35 * There are two important structures in this library: @c lldpctl_conn_t which
36 * represents a connection and @c lldpctl_atom_t which represents a piece of
37 * information. Those types are opaque. No direct access to them should be done.
39 * The library is expected to be reentrant and therefore thread-safe. It is
40 * however not expected that a connection to be used in several thread
41 * simultaneously. This also applies to the different pieces of information
42 * gathered through this connection. Several connection to lldpd can be used
45 * The first step is to establish a connection. See @ref lldpctl_connection for
46 * more information about this. The next step is to query the lldpd daemon. See
47 * @ref lldpctl_atoms on how to do this.
49 * `liblldpctl` tries to handle errors in a coherent way. Any function returning
50 * a pointer will return @c NULL on error and the last error can be retrieved
51 * through @ref lldpctl_last_error() function. Most functions returning integers
52 * will return a negative integer representing the error if something goes
53 * wrong. The use of @ref lldpctl_last_error() allows one to check if this is a
54 * real error if there is a doubt. See @ref lldpctl_errors_logs for more about
66 #include <sys/types.h>
69 * @defgroup lldpctl_connection Managing connection to lldpd
71 * Connection with lldpd.
73 * This library does not handle IO. They are delegated to a set of functions to
74 * allow a user to specify exactly how IO should be done. A user is expected to
75 * provide two functions: the first one is called when the library requests
76 * incoming data, the other one when it requests outgoing data. Moreover, the
77 * user is also expected to call the appropriate functions when data comes back
78 * (@ref lldpctl_recv()) or needs to be sent (@ref lldpctl_send()).
80 * Because the most common case is synchronous IO, `liblldpctl` will use classic
81 * synchronous IO with the Unix socket if no IO functions are provided by the
82 * user. For all other cases, the user must provide the appropriate functions.
84 * A connection should be allocated by using @ref lldpctl_new(). It needs to be
85 * released with @ref lldpctl_release().
91 * Get default transport name.
93 * Currently, this is the default location of the Unix socket.
95 const char *lldpctl_get_default_transport(void);
98 * Structure referencing a connection with lldpd.
100 * This structure should be handled as opaque. It can be allocated
101 * with @c lldpctl_new() and the associated resources will be freed
102 * with @c lldpctl_release().
104 typedef struct lldpctl_conn_t lldpctl_conn_t
;
107 * Callback function invoked to send data to lldpd.
109 * @param conn Handle to the connection to lldpd.
110 * @param data Bytes to be sent.
111 * @param length Length of provided data.
112 * @param user_data Provided user data.
113 * @return The number of bytes really sent or either @c LLDPCTL_ERR_WOULDBLOCK
114 * if no bytes can be sent without blocking or @c
115 * LLDPCTL_ERR_CALLBACK_FAILURE for other errors.
117 typedef ssize_t (*lldpctl_send_callback
)(lldpctl_conn_t
*conn
, const uint8_t *data
,
118 size_t length
, void *user_data
);
121 * Callback function invoked to receive data from lldpd.
123 * @param conn Handle to the connection to lldpd.
124 * @param data Buffer for receiving data
125 * @param length Maximum bytes we can receive
126 * @param user_data Provided user data.
127 * @return The number of bytes really received or either @c
128 * LLDPCTL_ERR_WOULDBLOCK if no bytes can be received without blocking,
129 * @c LLDPCTL_ERR_CALLBACK_FAILURE for other errors or @c
130 * LLDPCTL_ERR_EOF if end of file was reached.
132 typedef ssize_t (*lldpctl_recv_callback
)(lldpctl_conn_t
*conn
, const uint8_t *data
,
133 size_t length
, void *user_data
);
136 * Function invoked when additional data is available from lldpd.
138 * This function should be invoked in case of asynchronous IO when new data is
139 * available from lldpd (expected or unexpected).
141 * @param conn Handle to the connection to lldpd.
142 * @param data Data received from lldpd.
143 * @param length Length of data received.
144 * @return The number of bytes available or a negative integer if an error has
145 * occurred. 0 is not an error. It usually means that a notification has
148 ssize_t
lldpctl_recv(lldpctl_conn_t
*conn
, const uint8_t *data
, size_t length
);
151 * Function invoked when there is an opportunity to send data to lldpd.
153 * This function should be invoked in case of asynchronous IO when new data can
154 * be written to lldpd.
156 * @param conn Handle to the connection to lldpd.
157 * @return The number of bytes processed or a negative integer if an error has
160 ssize_t
lldpctl_send(lldpctl_conn_t
*conn
);
163 * Function invoked to see if there's more data to be processed in the buffer.
165 * This function should be invoked to check for notifications in the data that
166 * has already been read. Its used typically for asynchronous connections.
168 * @param conn Handle to the connection to lldpd.
169 * @return 0 to indicate maybe more data is available for processing
170 * !0 to indicate no data or insufficient data for processing
172 int lldpctl_process_conn_buffer(lldpctl_conn_t
*conn
);
175 * Allocate a new handler for connecting to lldpd.
177 * @param send Callback to be used when sending new data is requested.
178 * @param recv Callback to be used when receiving new data is requested.
179 * @param user_data Data to pass to callbacks.
180 * @return An handler to be used to connect to lldpd or @c NULL in
181 * case of error. In the later case, the error is probable an
182 * out of memory condition.
184 * The allocated handler can be released with @c lldpctl_release(). If the
185 * provided parameters are both @c NULL, default synchronous callbacks will be
188 lldpctl_conn_t
*lldpctl_new(lldpctl_send_callback send
, lldpctl_recv_callback recv
,
192 * Allocate a new handler for connecting to lldpd.
194 * @param ctlname the Unix-domain socket to connect to lldpd.
195 * @param send Callback to be used when sending new data is requested.
196 * @param recv Callback to be used when receiving new data is requested.
197 * @param user_data Data to pass to callbacks.
198 * @return An handler to be used to connect to lldpd or @c NULL in
199 * case of error. In the later case, the error is probable an
200 * out of memory condition.
202 * The allocated handler can be released with @c lldpctl_release(). If the
203 * provided parameters are both @c NULL, default synchronous callbacks will be
206 lldpctl_conn_t
*lldpctl_new_name(const char *ctlname
, lldpctl_send_callback send
,
207 lldpctl_recv_callback recv
, void *user_data
);
210 * Release resources associated with a connection to lldpd.
212 * @param conn Previously allocated handler to a connection to lldpd.
213 * @return 0 on success or a negative integer
217 int lldpctl_release(lldpctl_conn_t
*conn
);
221 * @defgroup lldpctl_errors_logs Errors and logs handling
223 * Error codes and logs handling.
225 * When a function returns a pointer, it may return @c NULL to indicate an error
226 * condition. In this case, it is possible to use @ref lldpctl_last_error() to
227 * get the related error code which is one of the values in @ref lldpctl_error_t
228 * enumeration. For display purpose @ref lldpctl_strerror() may be used to
229 * translate this error code.
231 * When a function returns an integer, it may return a negative value. It
232 * usually means this is an error but some functions may return a legitimate
233 * negative value (for example @ref lldpctl_atom_get_int()). When there is a
234 * doubt, @ref lldpctl_last_error() should be checked.
236 * An error is attached to a connection. If there is no connection, no error
237 * handling is available. Most functions use a connection or an atom as first
238 * argument and therefore are attached to a connection. To get the connection
239 * related to an atom, use @ref lldpctl_atom_get_connection().
241 * Also have a look at @ref lldpctl_log_callback() function if you want a custom
248 * Set up log handlers.
250 * By default, liblldpctl will log to stderr. The following function will
251 * register another callback for this purpose. Messages logged through this
252 * callback may be cryptic. They are targeted for the developer. Message for end
253 * users should rely on return codes.
255 void lldpctl_log_callback(void (*cb
)(int severity
, const char *msg
));
260 * By default, liblldpctl will only log warnings. The following function allows
261 * to increase verbosity. This function has no effect if callbacks are
262 * registered with the previous function.
264 * @param level Level of verbosity (1 = warnings, 2 = info, 3 = debug).
266 void lldpctl_log_level(int level
);
269 * Possible error codes for functions that return negative integers on
270 * this purpose or for @c lldpctl_last_error().
274 * No error has happened (yet).
276 LLDPCTL_NO_ERROR
= 0,
278 * A IO related operation would block if performed.
280 LLDPCTL_ERR_WOULDBLOCK
= -501,
282 * A IO related operation has reached a end of file condition.
284 LLDPCTL_ERR_EOF
= -502,
286 * The requested information does not exist. For example, when
287 * requesting an inexistent information from an atom.
289 LLDPCTL_ERR_NOT_EXIST
= -503,
291 * Cannot connect to the lldpd daemon. This error only happens with
292 * default synchronous handlers.
294 LLDPCTL_ERR_CANNOT_CONNECT
= -504,
296 * Atom is of incorrect type for the requested operation.
298 LLDPCTL_ERR_INCORRECT_ATOM_TYPE
= -505,
300 * An error occurred during serialization of message.
302 LLDPCTL_ERR_SERIALIZATION
= -506,
304 * The requested operation cannot be performed because we have another
305 * operation already running.
307 LLDPCTL_ERR_INVALID_STATE
= -507,
309 * The provided atom cannot be iterated.
311 LLDPCTL_ERR_CANNOT_ITERATE
= -508,
313 * The provided value is invalid.
315 LLDPCTL_ERR_BAD_VALUE
= -509,
317 * No new element can be created for this element.
319 LLDPCTL_ERR_CANNOT_CREATE
= -510,
321 * The library is under unexpected conditions and cannot process
322 * any further data reliably.
324 LLDPCTL_ERR_FATAL
= -900,
326 * Out of memory condition. Things may get havoc here but we
327 * should be able to recover.
329 LLDPCTL_ERR_NOMEM
= -901,
331 * An error occurred in a user provided callback.
333 LLDPCTL_ERR_CALLBACK_FAILURE
= -902,
335 * The callback was forced to unblock.
337 LLDPCTL_ERR_CALLBACK_UNBLOCK
= -903
341 * Describe a provided error code.
343 * @param error Error code to be described.
344 * @return Statically allocated string describing the error.
346 const char *lldpctl_strerror(lldpctl_error_t error
);
349 * Get the last error associated to a connection to lldpd.
351 * @param conn Previously allocated handler to a connection to lldpd.
352 * @return 0 if no error is currently registered. A negative integer
355 * For functions returning int, this function will return the same
356 * error number. For functions returning something else, you can use
357 * this function to get the appropriate error number.
359 lldpctl_error_t
lldpctl_last_error(lldpctl_conn_t
*conn
);
362 * Describe the last error associate to a connection.
364 * @param conn Previously allocated handler to a connection to lldpd.
365 * @return Statically allocated string describing the error
367 #define lldpctl_last_strerror(conn) lldpctl_strerror(lldpctl_last_error(conn))
371 * @defgroup lldpctl_atoms Extracting information: atoms
373 * Information retrieved from lldpd is represented as an atom.
375 * This is an opaque structure that can be passed along some functions to
376 * transmit chassis, ports, VLAN and other information related to LLDP. Most
377 * information are extracted using @c lldpctl_atom_get(), @c
378 * lldpctl_atom_get_str(), @c lldpctl_atom_get_buffer() or @c
379 * lldpctl_atom_get_int(), unless some IO with lldpd is needed to retrieve the
380 * requested information. In this case, there exists an appropriate function to
381 * convert the "deferred" atom into a normal one (like @c lldpctl_get_port()).
383 * For some information, setters are also available: @c lldpctl_atom_set(), @c
384 * lldpctl_atom_set_str(), @c lldpctl_atom_set_buffer() or @c
385 * lldpctl_atom_set_int(). Unlike getters, some of those may require IO to
386 * achieve their goal.
388 * An atom is reference counted. The semantics are quite similar to Python and
389 * you must be careful of the ownership of a reference. It is possible to own a
390 * reference by calling @c lldpctl_atom_inc_ref(). Once the atom is not needed
391 * any more, you can abandon ownership with @c lldpctl_atom_dec_ref(). Unless
392 * documented otherwise, a function returning an atom will return a new
393 * reference (the ownership is assigned to the caller, no need to call @c
394 * lldpctl_atom_inc_ref()). Unless documented otherwise, when providing an atom
395 * to a function, the atom is usually borrowed (no change in reference
396 * counting). Currently, no function will steal ownership.
398 * It is quite important to use the reference counting functions
399 * correctly. Segfaults or memory leaks may occur otherwise. Once the reference
400 * count reaches 0, the atom is immediately freed. Reusing it will likely lead
401 * to memory corruption.
407 * Structure representing an element (chassis, port, VLAN, ...)
409 * @see lldpctl_atom_inc_ref(), lldpctl_atom_dec_ref().
411 typedef struct lldpctl_atom_t lldpctl_atom_t
;
414 * Structure representing a map from an integer to a character string.
416 * @see lldpctl_key_get_map().
418 typedef const struct {
424 * Return the reference to connection with lldpd.
426 * @param atom The atom we want reference from.
427 * @return The reference to the connection to lldpd.
429 * Each atom contains an internal reference to the corresponding connection to
430 * lldpd. Use this function to get it.
432 lldpctl_conn_t
*lldpctl_atom_get_connection(lldpctl_atom_t
*atom
);
435 * Increment reference count for an atom.
437 * @param atom Atom we which to increase reference count.
439 void lldpctl_atom_inc_ref(lldpctl_atom_t
*atom
);
442 * Decrement reference count for an atom.
444 * @param atom Atom we want to decrease reference count. Can be @c NULL. In this
445 * case, nothing happens.
447 * When the reference count becomes 0, the atom is freed.
449 void lldpctl_atom_dec_ref(lldpctl_atom_t
*atom
);
452 * Possible events for a change (notification).
454 * @see lldpctl_watch_callback2
457 lldpctl_c_deleted
, /**< The neighbor has been deleted */
458 lldpctl_c_updated
, /**< The neighbor has been updated */
459 lldpctl_c_added
, /**< This is a new neighbor */
463 * Callback function invoked when a change is detected.
465 * @param conn Connection with lldpd. Should not be used.
466 * @param type Type of change detected.
467 * @param interface Physical interface on which the change has happened.
468 * @param neighbor Changed neighbor.
469 * @param data Data provided when registering the callback.
471 * The provided interface and neighbor atoms are stolen by the callback: their
472 * reference count are decremented when the callback ends. If you want to keep a
473 * reference to it, be sure to increment the reference count in the callback.
475 * @warning The provided connection should not be used at all. Do not use @c
476 * lldpctl_atom_set_*() functions on @c interface or @c neighbor either. If you
477 * do, you will get a @c LLDPCTL_ERR_INVALID_STATE error.
479 * @see lldpctl_watch_callback
481 typedef void (*lldpctl_change_callback
)(lldpctl_conn_t
*conn
, lldpctl_change_t type
,
482 lldpctl_atom_t
*interface
, lldpctl_atom_t
*neighbor
, void *data
);
485 * Callback function invoked when a change is detected.
487 * @param type Type of change detected.
488 * @param interface Physical interface on which the change has happened.
489 * @param neighbor Changed neighbor.
490 * @param data Data provided when registering the callback.
492 * The provided interface and neighbor atoms are stolen by the callback: their
493 * reference count are decremented when the callback ends. If you want to keep a
494 * reference to it, be sure to increment the reference count in the callback.
496 * @see lldpctl_watch_callback2
498 typedef void (*lldpctl_change_callback2
)(lldpctl_change_t type
,
499 lldpctl_atom_t
*interface
, lldpctl_atom_t
*neighbor
, void *data
);
502 * Register a callback to be called on changes.
504 * @param conn Connection with lldpd.
505 * @param cb Replace the current callback with the provided one.
506 * @param data Data that will be passed to the callback.
507 * @return 0 in case of success or -1 in case of errors.
509 * This function will register the necessity to push neighbor changes to lldpd
510 * and therefore will issue IO operations. The error code could then be @c
511 * LLDPCTL_ERR_WOULDBLOCK.
513 * @warning Once a callback is registered, the connection shouldn't be used for
514 * anything else than receiving notifications. If you do, you will get a @c
515 * LLDPCTL_ERR_INVALID_STATE error.
517 * @deprecated This function is deprecated and lldpctl_watch_callback2 should be
520 int lldpctl_watch_callback(lldpctl_conn_t
*conn
, lldpctl_change_callback cb
, void *data
)
521 __attribute__((deprecated
));
524 * Register a callback to be called on changes.
526 * @param conn Connection with lldpd.
527 * @param cb Replace the current callback with the provided one.
528 * @param data Data that will be passed to the callback.
529 * @return 0 in case of success or -1 in case of errors.
531 * This function will register the necessity to push neighbor changes to lldpd
532 * and therefore will issue IO operations. The error code could then be @c
533 * LLDPCTL_ERR_WOULDBLOCK.
535 * @warning Once a callback is registered, the connection shouldn't be used for
536 * anything else than receiving notifications. If you do, you will get a @c
537 * LLDPCTL_ERR_INVALID_STATE error.
539 int lldpctl_watch_callback2(lldpctl_conn_t
*conn
, lldpctl_change_callback2 cb
,
543 * Wait for the next change.
545 * @param conn Connection with lldpd.
546 * @return 0 on success or a negative integer in case of error.
548 * This function will return once a change has been detected. It is only useful
549 * as a main loop when using the builtin blocking IO mechanism.
551 int lldpctl_watch(lldpctl_conn_t
*conn
);
554 * Unblock another thread that's waiting for the next change on that synchronous
555 * callback connection.
557 * @param conn Synchronous callback connection with lldpd.
559 * If some thread is blocked at @ref lldpctl_watch() with the same synchronous
560 * callback @p conn, then this function will unblock it. Otherwise, this
561 * function will have no effect. This function is signal-safe.
563 void lldpctl_watch_sync_unblock(lldpctl_conn_t
*conn
);
566 * @defgroup liblldpctl_atom_get_special Retrieving atoms from lldpd
568 * Special access functions.
570 * Most information can be retrieved through @ref lldpctl_atom_get(), @ref
571 * lldpctl_atom_get_int(), @ref lldpctl_atom_get_str() or @ref
572 * lldpctl_atom_get_buffer() but some information can only be retrieved through
573 * special functions because IO operation is needed (and also, for some of them,
574 * because we don't have an atom yet).
580 * Retrieve global configuration of lldpd daemon.
582 * @param conn Connection with lldpd.
583 * @return The global configuration or @c NULL if an error happened.
585 * This function will make IO with the daemon to get the
586 * configuration. Depending on the IO model, information may not be available
587 * right now and the function should be called again later. If @c NULL is
588 * returned, check the last error. If it is @c LLDPCTL_ERR_WOULDBLOCK, try again
591 lldpctl_atom_t
*lldpctl_get_configuration(lldpctl_conn_t
*conn
);
594 * Retrieve the list of available interfaces.
596 * @param conn Previously allocated handler to a connection to lldpd.
597 * @return The list of available ports or @c NULL if an error happened.
599 * This function will make IO with the daemon to get the list of
600 * ports. Depending on the IO model, information may not be available right now
601 * and the function should be called again later. If @c NULL is returned, check
602 * what the last error is. If it is @c LLDPCTL_ERR_WOULDBLOCK, try again later
603 * (when more data is available).
605 * The list of available ports can be iterated with @ref lldpctl_atom_foreach().
607 lldpctl_atom_t
*lldpctl_get_interfaces(lldpctl_conn_t
*conn
);
610 * Retrieve the information related to the local chassis.
612 * @param conn Previously allocated handler to a connection to lldpd.
613 * @return Atom related to the local chassis which may be used in subsequent functions.
615 * This function may have to do IO to get the information related to the local
616 * chassis. Depending on the IO mode, information may not be available right now
617 * and the function should be called again later. If @c NULL is returned, check
618 * what the last error is. If it is @c LLDPCTL_ERR_WOULDBLOCK, try again later
619 * (when more data is available).
621 lldpctl_atom_t
*lldpctl_get_local_chassis(lldpctl_conn_t
*conn
);
624 * Retrieve the information related to a given interface.
626 * @param port The port we want to retrieve information from. This port is an
627 * atom retrieved from an iteration on @c lldpctl_get_interfaces().
628 * @return Atom related to this port which may be used in subsequent functions.
630 * This function may have to do IO to get the information related to the given
631 * port. Depending on the IO mode, information may not be available right now
632 * and the function should be called again later. If @c NULL is returned, check
633 * what the last error is. If it is @c LLDPCTL_ERR_WOULDBLOCK, try again later
634 * (when more data is available).
636 lldpctl_atom_t
*lldpctl_get_port(lldpctl_atom_t
*port
);
639 * Retrieve the default port information.
641 * This port contains default settings whenever a new port needs to be created.
643 * @param conn Previously allocated handler to a connection to lldpd.
644 * @return Atom of the default port which may be used in subsequent functions.
646 * This function may have to do IO to get the information related to the given
647 * port. Depending on the IO mode, information may not be available right now
648 * and the function should be called again later. If @c NULL is returned, check
649 * what the last error is. If it is @c LLDPCTL_ERR_WOULDBLOCK, try again later
650 * (when more data is available).
652 lldpctl_atom_t
*lldpctl_get_default_port(lldpctl_conn_t
*conn
);
657 * Piece of information that can be retrieved from/written to an atom.
659 * Each piece of information can potentially be retrieved as an atom (A), a
660 * string (S), a buffer (B) or an integer (I). Additionally, when an information
661 * can be retrieved as an atom, it is usually iterable (L). When an atom can be
662 * retrieved as a string and as an additional type, the string is expected to be
663 * formatted. For example, the MAC address of a local port can be retrieved as a
664 * buffer and a string. As a string, you'll get something like
665 * "00:11:22:33:44:55". Also, all values that can be get as an integer or a
666 * buffer can be get as a string too. There is no special formatting in this
667 * case. "(BS)" means that the string get a special appropriate format.
669 * The name of a key is an indication on the type of atom that information can
670 * be extracted from. For example, @c lldpctl_k_med_policy_type can be extracted
671 * from an atom you got by iterating on @c lldpctl_k_port_med_policies. On the
672 * other hand, @c lldpctl_k_port_descr and @c lldpctl_k_chassis can be retrieved
673 * from an atom retrieved either by iterating @c lldpctl_k_port_neighbors or
674 * with @c lldpctl_get_port().
676 * Some values may be written. They are marked with (W). Such a change may or
677 * may not be transmitted immediately. If they are not transmitted immediately,
678 * this means that the resulting atom should be written to another atom. For
679 * example, when writing @c lldpctl_k_med_policy_tagged, you need to write the
680 * resulting atom to @c lldpctl_k_port_med_policies. If the change is
681 * transmitted immediately, you need to check the error status of the connection
682 * to know if it has been transmitted correctly. Notably, if you get @c
683 * LLDPCTL_ERR_WOULDBLOCK, you need to try again later. Usually, changes are
684 * transmitted immediately. The exception are changes that need to be grouped to
685 * be consistent, like a LLDP MED location. When a change is transmitted
686 * immediately, it is marked with (O). @c lldpctl_atom_set_str() may accept a @c
687 * NULL value. This case is marked with (N) and usually reset the item to the
688 * default value or no value.
690 * Some values may also be created. They are flagged with (C). This only applies
691 * to elements that can be iterated (L) and written (W). The element created
692 * still needs to be appended to the list by being written to it. The creation
693 * is done with @c lldpctl_atom_create().
695 * An atom marked with (S) can be retrieved as a string only. It cannot be
696 * written. An atom marked with (IS) can be retrieved as an integer and features
697 * an appropriate representation as a string (usually, the name of a constant)
698 * which is more meaningful than just the integer. An atom marked as (I) can be
699 * retrieved as an integer and as a string. In the later case, this is just a
700 * string representation of the integer. An atom marked with (AL) can be
701 * retrieved as an atom only and can be iterated over. This is usually a list of
702 * things. An atom marked (I,W) can be read as an integer or a string and can be
703 * written as an integer. The change would not be committed until the atom is
704 * written to the nearest atom supporting (A,WO) operation (eventually with an
705 * indirection, i.e first write to a (A,W), then to a (A,WO)).
708 lldpctl_k_config_tx_interval
, /**< `(I,WO)` Transmit interval. When set to -1,
709 it is meant to transmit now. */
710 lldpctl_k_config_receiveonly
, /**< `(I)` Receive only mode */
711 lldpctl_k_config_mgmt_pattern
, /**< `(S,WON)` Pattern to choose the management
713 lldpctl_k_config_iface_pattern
, /**< `(S,WON)` Pattern of enabled interfaces */
714 lldpctl_k_config_cid_pattern
, /**< `(S)` Interface pattern to choose the chassis
716 lldpctl_k_config_description
, /**< `(S,WON)` Chassis description overridden */
717 lldpctl_k_config_platform
, /**< `(S,WON)` Platform description overridden (CDP)
719 lldpctl_k_config_hostname
, /**< `(S,WON)` System name overridden */
720 lldpctl_k_config_advertise_version
, /**< `(I)` Advertise version */
721 lldpctl_k_config_lldpmed_noinventory
, /**< `(I)` Disable LLDP-MED inventory */
722 lldpctl_k_config_paused
, /**< `(I,WO)` lldpd is paused */
723 lldpctl_k_config_fast_start_enabled
, /**< `(I,WO)` Is fast start enabled */
724 lldpctl_k_config_fast_start_interval
, /**< `(I,WO)` Start fast transmit interval
726 lldpctl_k_config_ifdescr_update
, /**< `(I,WO)` Enable or disable setting
727 interface description */
728 lldpctl_k_config_iface_promisc
, /**< `(I,WO)` Enable or disable promiscuous mode
730 lldpctl_k_config_chassis_cap_advertise
, /**< `(I,WO)` Enable or disable chassis
731 capabilities advertisement */
732 lldpctl_k_config_chassis_mgmt_advertise
, /**< `(I,WO)` Enable or disable
733 management addresses advertisement
735 lldpctl_k_config_cid_string
, /**< `(S,WON)` User defined string for the chassis
737 lldpctl_k_config_perm_iface_pattern
, /**< `(S,WON)` Pattern of permanent
739 lldpctl_k_config_tx_interval_ms
, /**< `(I,WO)` Transmit interval in
740 milliseconds. Set to -1 to transmit now. */
741 lldpctl_k_config_chassis_cap_override
, /**< `(I,WO)` Override chassis
744 lldpctl_k_interface_name
= 1000, /**< `(S)` The interface name. */
746 lldpctl_k_port_name
=
747 1100, /**< `(S)` The port name. Only works for a local port. */
748 lldpctl_k_port_index
, /**< `(I)` The port index. Only works for a local port. */
750 * `(AL)` The list of known neighbors for this port.
752 * A neighbor is in fact a remote port.
754 lldpctl_k_port_neighbors
= 1200,
755 lldpctl_k_port_protocol
, /**< `(IS)` The protocol that was used to retrieve this
757 lldpctl_k_port_age
, /**< `(I)` Age of information, seconds from epoch. */
758 lldpctl_k_port_id_subtype
, /**< `(IS)` The subtype ID of this port. */
759 lldpctl_k_port_id
, /**< `(BS,WO)` The ID of this port. */
760 lldpctl_k_port_descr
, /**< `(S,WO)` The description of this port. */
761 lldpctl_k_port_hidden
, /**< `(I)` Is this port hidden (or should it be
763 lldpctl_k_port_status
, /**< `(IS,WO)` Operational status of this (local) port */
764 lldpctl_k_port_chassis
, /**< `(A)` Chassis associated to the port */
765 lldpctl_k_port_ttl
, /**< `(I)` TTL for port, 0 if info is attached to chassis */
766 lldpctl_k_port_vlan_tx
, /**< `(I,W)` VLAN tag for TX on port, -1 VLAN disabled
769 lldpctl_k_port_dot3_mfs
= 1300, /**< `(I)` MFS */
770 lldpctl_k_port_dot3_aggregid
, /**< `(I)` Port aggregation ID */
771 lldpctl_k_port_dot3_autoneg_support
, /**< `(I)` Autonegotiation support. */
772 lldpctl_k_port_dot3_autoneg_enabled
, /**< `(I)` Autonegotiation enabled. */
773 lldpctl_k_port_dot3_autoneg_advertised
, /**< `(I)` Advertised protocols. See
774 `LLDP_DOT3_LINK_AUTONEG_*` */
775 lldpctl_k_port_dot3_mautype
, /**< `(IS)` Current MAU type. See `LLDP_DOT3_MAU_*`
778 lldpctl_k_port_dot3_power
= 1400, /**< `(A,WO)` Dot3 power related stuff. */
779 lldpctl_k_dot3_power_devicetype
, /**< `(IS,W)` Device type. See
780 `LLDP_DOT3_POWER_PSE/PD` */
781 lldpctl_k_dot3_power_supported
, /**< `(I,W)` Is MDI power supported. */
782 lldpctl_k_dot3_power_enabled
, /**< `(I,W)` Is MDI power enabled. */
783 lldpctl_k_dot3_power_paircontrol
, /**< `(I,W)` Pair-control enabled? */
784 lldpctl_k_dot3_power_pairs
, /**< `(IS,W)` See `LLDP_DOT3_POWERPAIRS_*` */
785 lldpctl_k_dot3_power_class
, /**< `(IS,W)` Power class. */
786 lldpctl_k_dot3_power_type
, /**< `(I,W)` 802.3AT power type */
787 lldpctl_k_dot3_power_source
, /**< `(IS,W)` 802.3AT power source */
788 lldpctl_k_dot3_power_priority
, /**< `(IS,W)` 802.3AT power priority */
789 lldpctl_k_dot3_power_allocated
, /**< `(I,W)` 802.3AT power allocated */
790 lldpctl_k_dot3_power_requested
, /**< `(I,W)` 802.3AT power requested */
792 /* 802.3bt additions */
793 lldpctl_k_dot3_power_pd_4pid
, /**< `(IS)` 802.3BT both modes supported? */
794 lldpctl_k_dot3_power_requested_a
, /**< `(I)` 802.3BT power value requested for
796 lldpctl_k_dot3_power_requested_b
, /**< `(I)` 802.3BT power value requested for
798 lldpctl_k_dot3_power_allocated_a
, /**< `(I)` 802.3BT power value allocated for
800 lldpctl_k_dot3_power_allocated_b
, /**< `(I)` 802.3BT power value allocated for
802 lldpctl_k_dot3_power_pse_status
, /**< `(IS)` 802.3BT PSE powering status */
803 lldpctl_k_dot3_power_pd_status
, /**< `(IS)` 802.3BT PD powering status */
804 lldpctl_k_dot3_power_pse_pairs_ext
, /**< `(IS)` 802.3BT PSE power pairs */
805 lldpctl_k_dot3_power_class_a
, /**< `(IS)` 802.3BT power class for A */
806 lldpctl_k_dot3_power_class_b
, /**< `(IS)` 802.3BT power class for B */
807 lldpctl_k_dot3_power_class_ext
, /**< `(IS)` 802.3BT power class */
808 lldpctl_k_dot3_power_type_ext
, /**< `(IS)` 802.3BT power type */
809 lldpctl_k_dot3_power_pd_load
, /**< `(IS)` 802.3BT dualsig isolated? */
810 lldpctl_k_dot3_power_pse_max
, /**< `(I)` 802.3BT maximum available power */
812 lldpctl_k_port_vlan_pvid
= 1500, /**< `(I)` Primary VLAN ID */
813 lldpctl_k_port_vlans
, /**< `(AL)` List of VLAN */
814 lldpctl_k_vlan_id
, /**< `(I)` VLAN ID */
815 lldpctl_k_vlan_name
, /**< `(S)` VLAN name */
817 lldpctl_k_port_ppvids
= 1600, /**< `(AL)` List of PPVIDs */
818 lldpctl_k_ppvid_status
, /**< `(I)` Status of PPVID (see `LLDP_PPVID_CAP_*`) */
819 lldpctl_k_ppvid_id
, /**< `(I)` ID of PPVID */
821 lldpctl_k_port_pis
= 1700, /**< `(AL)` List of PIDs */
822 lldpctl_k_pi_id
, /**< `(B)` PID value */
824 lldpctl_k_chassis_index
= 1800, /**< `(I)` The chassis index. */
825 lldpctl_k_chassis_id_subtype
, /**< `(IS)` The subtype ID of this chassis. */
826 lldpctl_k_chassis_id
, /**< `(BS)` The ID of this chassis. */
827 lldpctl_k_chassis_name
, /**< `(S)` The name of this chassis. */
828 lldpctl_k_chassis_descr
, /**< `(S)` The description of this chassis. */
829 lldpctl_k_chassis_cap_available
, /**< `(I)` Available capabilities (see
831 lldpctl_k_chassis_cap_enabled
, /**< `(I)` Enabled capabilities (see
833 lldpctl_k_chassis_mgmt
, /**< `(AL)` List of management addresses */
834 lldpctl_k_chassis_ttl
, /**< Deprecated */
836 lldpctl_k_chassis_med_type
=
837 1900, /**< `(IS)` Chassis MED type. See `LLDP_MED_CLASS_*` */
838 lldpctl_k_chassis_med_cap
, /**< `(I)` Available MED capabilities. See
840 lldpctl_k_chassis_med_inventory_hw
, /**< `(S,W)` LLDP MED inventory "Hardware
842 lldpctl_k_chassis_med_inventory_sw
, /**< `(S,W)` LLDP MED inventory "Software
844 lldpctl_k_chassis_med_inventory_fw
, /**< `(S,W)` LLDP MED inventory "Firmware
846 lldpctl_k_chassis_med_inventory_sn
, /**< `(S,W)` LLDP MED inventory "Serial
848 lldpctl_k_chassis_med_inventory_manuf
, /**< `(S,W)` LLDP MED inventory
850 lldpctl_k_chassis_med_inventory_model
, /**< `(S,W)` LLDP MED inventory "Model"
852 lldpctl_k_chassis_med_inventory_asset
, /**< `(S,W)` LLDP MED inventory "Asset
855 lldpctl_k_port_med_policies
=
856 2000, /**< `(AL,WO)` MED policies attached to a port. */
857 lldpctl_k_med_policy_type
, /**< `(IS,W)` MED policy app type. See
858 `LLDP_MED_APPTYPE_*`. 0 if a policy is not
860 lldpctl_k_med_policy_unknown
, /**< `(I,W)` Is MED policy defined? */
861 lldpctl_k_med_policy_tagged
, /**< `(I,W)` MED policy tagging */
862 lldpctl_k_med_policy_vid
, /**< `(I,W)` MED policy VID */
863 lldpctl_k_med_policy_priority
, /**< `(I,W)` MED policy priority */
864 lldpctl_k_med_policy_dscp
, /**< `(I,W)` MED policy DSCP */
866 lldpctl_k_port_med_locations
=
867 2100, /**< `(AL,WO)` MED locations attached to a port. */
868 lldpctl_k_med_location_format
, /**< `(IS,W)` MED location format. See
869 * `LLDP_MED_LOCFORMAT_*`. 0 if this
870 * location is not defined. When written,
871 * the following fields will be zeroed
873 lldpctl_k_med_location_geoid
, /**< `(IS,W)` MED geoid. See
874 `LLDP_MED_LOCATION_GEOID_*`. Only if format is
876 lldpctl_k_med_location_latitude
, /**< `(S,W)` MED latitude. Only if format is
878 lldpctl_k_med_location_longitude
, /**< `(S,W)` MED longitude. Only if format is
880 lldpctl_k_med_location_altitude
, /**< `(S,W)` MED altitude. Only if format is
882 lldpctl_k_med_location_altitude_unit
, /**< `(S,W)` MED altitude unit. See
883 * `LLDP_MED_LOCATION_ALTITUDE_UNIT_*`.
884 * Only if format is COORD. */
886 lldpctl_k_med_location_country
=
887 2200, /**< `(S,W)` MED country. Only if format is CIVIC. */
888 lldpctl_k_med_location_elin
, /**< `(S,W)` MED ELIN. Only if format is ELIN. */
890 lldpctl_k_med_location_ca_elements
=
891 2300, /**< `(AL,WC)` MED civic address elements. Only if format is CIVIC */
892 lldpctl_k_med_civicaddress_type
, /**< `(IS,W)` MED civic address type. */
893 lldpctl_k_med_civicaddress_value
, /**< `(S,W)` MED civic address value. */
895 lldpctl_k_port_med_power
= 2400, /**< `(A,WO)` LLDP-MED power related stuff. */
896 lldpctl_k_med_power_type
, /**< `(IS,W)` LLDP MED power device type. See
897 `LLDP_MED_POW_TYPE_*` */
898 lldpctl_k_med_power_source
, /**< `(IS,W)` LLDP MED power source. See
899 `LLDP_MED_POW_SOURCE_*` */
900 lldpctl_k_med_power_priority
, /**< `(IS,W)` LLDP MED power priority. See
901 `LLDP_MED_POW_PRIO_*` */
902 lldpctl_k_med_power_val
, /**< `(I,W)` LLDP MED power value */
904 lldpctl_k_mgmt_ip
= 3000, /**< `(S)` IP address */
905 lldpctl_k_mgmt_iface_index
= 30001, /**< `(I)` Interface index */
907 lldpctl_k_tx_cnt
= 4000, /**< `(I)` tx cnt. Only works for a local port. */
908 lldpctl_k_rx_cnt
, /**< `(I)` rx cnt. Only works for a local port. */
909 lldpctl_k_rx_discarded_cnt
, /**< `(I)` discarded cnt. Only works for a local
911 lldpctl_k_rx_unrecognized_cnt
, /**< `(I)` unrecognized cnt. Only works for a
913 lldpctl_k_ageout_cnt
, /**< `(I)` ageout cnt. Only works for a local port. */
914 lldpctl_k_insert_cnt
, /**< `(I)` insert cnt. Only works for a local port. */
915 lldpctl_k_delete_cnt
, /**< `(I)` delete cnt. Only works for a local port. */
916 lldpctl_k_config_tx_hold
, /**< `(I,WO)` Transmit hold interval. */
917 lldpctl_k_config_bond_slave_src_mac_type
, /**< `(I,WO)` bond slave src mac type.
919 lldpctl_k_config_lldp_portid_type
, /**< `(I,WO)` LLDP PortID TLV Subtype */
920 lldpctl_k_config_lldp_agent_type
, /**< `(I,WO)` LLDP agent type */
921 lldpctl_k_config_max_neighbors
, /**< `(I,WO)`Maximum number of neighbors per
924 lldpctl_k_custom_tlvs
= 5000, /**< `(AL)` custom TLVs */
925 lldpctl_k_custom_tlvs_clear
, /**< `(WO)` clear list of custom TLVs */
926 lldpctl_k_custom_tlv
, /**< `(AL,WO)` custom TLV **/
927 lldpctl_k_custom_tlv_oui
, /**< `(B,W)` custom TLV Organizationally Unique
928 Identifier. Default is 0 (3 bytes) */
929 lldpctl_k_custom_tlv_oui_subtype
, /**< `(I,W)` custom TLV subtype. Default is 0
931 lldpctl_k_custom_tlv_oui_info_string
, /**< `(BS,W)` custom TLV Organizationally
932 Unique Identifier Information String
934 lldpctl_k_custom_tlv_op
, /**< `(S,W)` custom TLV operation */
939 * Get a map related to a key.
941 * Many keys expect to be written with a discrete number of values. Take for
942 * example @c lldpctl_k_med_civicaddress_type, it can take any integer between 1
943 * and 128. However, each integer can be named. It can be useful for an
944 * application to get a translation between the integer that can be provided and
945 * a more human-readable name. This function allows to retrieve the
948 * @param key The piece of information we want a map from.
949 * @return The map or @c NULL if no map is available.
951 * The returned map has its last element set to 0. It is also expected that the
952 * string value can be used with a set operation. It will be translated to the
955 lldpctl_map_t
*lldpctl_key_get_map(lldpctl_key_t key
);
958 * Retrieve a bit of information as an atom.
960 * @param atom The atom we want to query.
961 * @param key The information we want from the atom.
962 * @return The atom representing the requested information or @c NULL if the
963 * information is not available.
965 * Not every value of @c info will be available as an atom. See the
966 * documentation of @c lldpctl_key_t for values accepting to be extracted as an
967 * atom. Usually, this is only iterable values or values representing a complex
970 * The provided atom is not a _borrowed_ reference. You need to decrement the
971 * reference count when you don't need it any more.
973 * As a convenience, this function will return @c NULL if the first parameter is
974 * @c NULL and no error will be raised.
976 lldpctl_atom_t
*lldpctl_atom_get(lldpctl_atom_t
*atom
, lldpctl_key_t key
);
979 * Set a bit of information with an atom.
981 * @param atom The atom we want to write to.
982 * @param key The key information we want to write.
983 * @param value The value of the information we want to write.
984 * @return The updated atom with the appropriate information.
986 * This function will return @c NULL in case of error. If the last error is @c
987 * LLDPCTL_ERR_WOULDBLOCK, the write should be retried later with the exact same
988 * parameters. LLDPCTL_ERR_BAD_VALUE is raised when the provided atom is not
991 lldpctl_atom_t
*lldpctl_atom_set(lldpctl_atom_t
*atom
, lldpctl_key_t key
,
992 lldpctl_atom_t
*value
);
995 * Retrieve a bit of information as a null-terminated string.
997 * @param atom The atom we want to query.
998 * @param key The information we want from the atom.
999 * @return The requested string or @c NULL if the information is not available.
1001 * Not every value of @c info will be available as a string. See the
1002 * documentation of @c lldpctl_key_t for values accepting to be extracted as a
1003 * string. Usually, only piece of information stored as string are available in
1004 * this form but sometimes, you can get a nice formatted string instead of an
1005 * integer with this function.
1007 * As a convenience, this function will return @c NULL if the first parameter is
1008 * @c NULL and no error will be raised.
1010 * The provided string may live inside the atom providing it. If you need it
1011 * longer, duplicate it.
1013 const char *lldpctl_atom_get_str(lldpctl_atom_t
*atom
, lldpctl_key_t key
);
1016 * Set a bit of information using a null-terminated string.
1018 * @param atom The atom we want to write to.
1019 * @param key The key information we want to write.
1020 * @param value The value of the information we want to write.
1021 * @return The updated atom with the appropriate information.
1023 * This function will return @c NULL in case of error. If the last error is @c
1024 * LLDPCTL_ERR_WOULDBLOCK, the write should be retried later with the exact same
1025 * parameters. LLDPCTL_ERR_BAD_VALUE is raised when the provided atom is not
1028 lldpctl_atom_t
*lldpctl_atom_set_str(lldpctl_atom_t
*atom
, lldpctl_key_t key
,
1032 * Retrieve a bit of information as a buffer.
1034 * @param atom The atom we want to query.
1035 * @param key The information we want from the atom.
1036 * @param[out] length The size of the returned buffer.
1037 * @return The requested buffer or @c NULL if the information is not available.
1039 * Not every value of @c info will be available as a buffer. See the
1040 * documentation of @c lldpctl_key_t for values accepting to be extracted as a
1041 * string. Usually, only piece of information stored as buffer are available in
1044 * As a convenience, this function will return @c NULL if the first parameter is
1045 * @c NULL and no error will be raised. If this function returns @c NULL, the
1046 * third parameter is set to 0.
1048 * The provided buffer may live inside the atom providing it. If you need it
1049 * longer, duplicate it.
1051 const uint8_t *lldpctl_atom_get_buffer(lldpctl_atom_t
*atom
, lldpctl_key_t key
,
1055 * Set a bit of information using a buffer
1057 * @param atom The atom we want to write to.
1058 * @param key The key information we want to write.
1059 * @param value The value of the information we want to write.
1060 * @param length The length of the provided buffer.
1061 * @return The updated atom with the appropriate information.
1063 * This function will return @c NULL in case of error. If the last error is @c
1064 * LLDPCTL_ERR_WOULDBLOCK, the write should be retried later with the exact same
1065 * parameters. LLDPCTL_ERR_BAD_VALUE is raised when the provided atom is not
1068 lldpctl_atom_t
*lldpctl_atom_set_buffer(lldpctl_atom_t
*atom
, lldpctl_key_t key
,
1069 const uint8_t *value
, size_t length
);
1072 * Retrieve a bit of information as an integer.
1074 * @param atom The atom we want to query.
1075 * @param key The information we want from the atom.
1076 * @return The requested integer or -1 if the information is not available
1078 * Not every value of @c info will be available as an integer. See the
1079 * documentation of @c lldpctl_key_t for values accepting to be extracted as a
1080 * string. Usually, only piece of information stored as an integer are available
1083 * Only @c lldpctl_last_error() can tell if the returned value is an error or
1084 * not. However, most values extracted from lldpd cannot be negative.
1086 long int lldpctl_atom_get_int(lldpctl_atom_t
*atom
, lldpctl_key_t key
);
1089 * Set a bit of information using an integer
1091 * @param atom The atom we want to write to.
1092 * @param key The key information we want to write.
1093 * @param value The value of the information we want to write.
1094 * @return The updated atom with the appropriate information.
1096 * This function will return @c NULL in case of error. If the last error is @c
1097 * LLDPCTL_ERR_WOULDBLOCK, the write should be retried later with the exact same
1098 * parameters. LLDPCTL_ERR_BAD_VALUE is raised when the provided atom is not
1101 lldpctl_atom_t
*lldpctl_atom_set_int(lldpctl_atom_t
*atom
, lldpctl_key_t key
,
1105 * @defgroup liblldpctl_atom_iter Iterating over atoms
1107 * Iterate over atoms (lists).
1112 * Iterator over an iterable atom (a list of ports, a list of VLAN, ...). When
1113 * an atom is a list, it can be iterated over to extract the appropriate values.
1115 * @see lldpctl_atom_iter(), lldpctl_atom_iter_next(), lldpctl_atom_iter_value()
1117 typedef struct lldpctl_atom_iter_t lldpctl_atom_iter_t
;
1120 * Return an iterator over a given atom.
1122 * If an atom is iterable (if it is a list, like a list of ports, a list of
1123 * VLAN, a list of neighbors), it is possible to iterate over it. First use this
1124 * function to get an iterator then use @c lldpctl_atom_iter_next() to get the
1125 * next item and @c lldpctl_atom_iter_value() to the actual item.
1127 * @param atom The atom we want to create an iterator from.
1128 * @return The iterator or @c NULL if an error happened or if the atom is empty
1129 * (check with @c lldpctl_last_error()).
1131 * As a convenience, if the provided atom is @c NULL, this function will return
1132 * @c NULL and no error will be raised.
1134 lldpctl_atom_iter_t
*lldpctl_atom_iter(lldpctl_atom_t
*atom
);
1137 * Return the next element of an iterator.
1139 * @param atom The atom we are currently iterating.
1140 * @param iter The iterator we want the next element from.
1141 * @return An iterator starting on the next element or @c NULL if we have no
1144 * @see lldpctl_atom_iter(), lldpctl_atom_iter_value().
1146 * As a convenience, if the provided atom is @c NULL, this function will return
1147 * @c NULL and no error will be raised.
1149 lldpctl_atom_iter_t
*lldpctl_atom_iter_next(lldpctl_atom_t
*atom
,
1150 lldpctl_atom_iter_t
*iter
);
1153 * Return the value of an iterator.
1155 * @param atom The atom we are currently iterating.
1156 * @param iter The iterator we want the next element from.
1157 * @return The atom currently associated with the iterator.
1159 * @see lldpctl_atom_iter(), lldpctl_atom_iter_next().
1161 lldpctl_atom_t
*lldpctl_atom_iter_value(lldpctl_atom_t
*atom
,
1162 lldpctl_atom_iter_t
*iter
);
1165 * Convenience macro to iterate over every value of an iterable object.
1167 * @param atom The atom you want to iterate on.
1168 * @param value Atom name that will be used to contain each value.
1170 * This macro behaves as a for loop. Moreover, at the end of each iteration, the
1171 * reference count of the provided value is decremented. If you need to use it
1172 * outside of the loop, you need to increment it.
1174 #define lldpctl_atom_foreach(atom, value) \
1175 for (lldpctl_atom_iter_t *iter##_LINE_ = lldpctl_atom_iter(atom); \
1176 iter##_LINE_ && (value = lldpctl_atom_iter_value(atom, iter##_LINE_)); \
1177 iter##_LINE_ = lldpctl_atom_iter_next(atom, iter##_LINE_), \
1178 lldpctl_atom_dec_ref(value))
1181 * Create a new value for an iterable element.
1183 * The value is meant to be appended using @c lldpctl_atom_set(). Currently,
1184 * there is no way to delete an element from a list. It is also not advisable to
1185 * use getters on a newly created object until it is fully initialized. If its
1186 * internal representation is using a buffer, it may not be initialized until
1189 * @param atom The atom we want to create a new element for.
1190 * @return The new element.
1192 lldpctl_atom_t
*lldpctl_atom_create(lldpctl_atom_t
*atom
);