Error codes and error handling

group errors

Definitions and descriptions of error codes, and error related functions.

Functions that can fail usually return an error code from lsdn_err_t. This is not very specific, so in addition, some functions allow you to specify a problem callback function. This is a user-defined function that gets called separately for every error encountered - such as when validating or committing the model.

Convenience functions are provided to dump error strings either to stderr or to a specified FILE.

Defines

LSDN_MAX_PROBLEM_REFS

Maximum number of problem items described simultaneously.

Configures size of the problem buffer in lsdn_context.

Typedefs

typedef void(*lsdn_problem_cb)(const struct lsdn_problem *diag, void *user)

Problem handler callback.

Parameters
  • diag: description of the problem.
  • user: user-specified data.

Enums

enum lsdn_err_t

Possible LSDN errors.

Values:

LSDNE_OK = 0

No error.

LSDNE_NOMEM

Out of memory.

LSDNE_PARSE

Parsing from string has failed.

Can occur when parsing IPs, MACs etc.

LSDNE_DUPLICATE

Duplicate name.

Can occur when setting name for a network, virt or phys.

LSDNE_NOIF

Interface does not exist.

Netlink error.

LSDNE_VALIDATE

Network model validation failed, and the old model is in effect.

LSDNE_COMMIT

Network model commit failed and a mix of old, new and dysfunctional objects are in effect.

You can retry the commit and it will work if the error was temporary.

The error could also be permanent, if, for example, a user have created a network interface that shares a name with what LSDN was going to use. In that case, you will be getting the error repeatedly. You can either ignore it or delete the failing part of the model.

LSDNE_INCONSISTENT

Cleanup operation has failed and this left an object in state inconsistent with the model.

This failure is more serious than LSDNE_COMMIT failure, since the commit operation can not be successfully retried. The only operation possible is to rebuild the whole model again.

enum lsdn_problem_code

Validation and commit errors.

Values:

LSDNP_PHYS_NOATTR

Missing attribute on a phys.

LSDNP_PHYS_DUPATTR

Duplicate attribute on two phys’s in the same network.

LSDNP_PHYS_INCOMPATIBLE_IPV

Incompatible IP versions in the same network.

LSDNP_PHYS_NOT_ATTACHED

Connecting a virt from a phys that is not attached to a network.

LSDNP_VIRT_NOIF

Interface specified for a virt does not exist.

LSDNP_VIRT_NOATTR

Missing attribute on a virt.

LSDNP_VIRT_DUPATTR

Duplicate attribute on two virts in the same network.

LSDNP_NET_BAD_NETTYPE

Incompatible networks on the same machine.

LSDNP_NET_BADID

Bad network ID.

LSDNP_NET_DUPID

Duplicate network ID.

LSDNP_VR_INCOMPATIBLE_MATCH

Two incompatible virt rules with the same priority.

LSDNP_VR_DUPLICATE_RULE

Duplicate virt rules.

Committing to netlink failed due to kernel error.

Decommitting to netlink failed due to kernel error and the state is now inconsistent.

LSDNP_COMMIT_NOMEM

Committing to netlink failed due to memory error.

LSDNP_NO_NLSOCK

Can not establish netlink communication.

LSDNP_RATES_INVALID

QoS has invalid parameters (both rate and burst must be positive).

See lsdn_qos_rate_t for correct parameters.

LSDNP_COUNT

Guard value.

See LSDN_ENUM for details.

enum lsdn_problem_ref_type

Problem reference type.

Values:

LSDNS_ATTR

Problem with attribute.

LSDNS_PHYS

Problem with lsdn_phys.

LSDNS_PA

Problem with lsdn_net and lsdn_phys combination.

LSDNS_NET

Problem with lsdn_net.

LSDNS_VIRT

Problem with lsdn_virt.

LSDNS_IF

Problem with a network interface.

LSDNS_NETID

Problem with vnet_id.

LSDNS_VR

Problem with lsdn_vr.

LSDNS_END

End of problem list.

Functions

void lsdn_problem_stderr_handler(const struct lsdn_problem * problem, void * user)

Problem handler that dumps problem descriptions to stderr.

Can be used as a callback in lsdn_commit, lsdn_validate, and any other place that takes lsdn_problem_cb.

When a problem is encountered, this handler will dump a human-readable description to stderr.

Parameters
  • problem: problem description.
  • user: user data for the callback. Unused.

void lsdn_problem_format(FILE * out, const struct lsdn_problem * problem)

Print problem description.

Constructs a string describing the problem and writes it out to out.

Parameters
  • out: output stream.
  • problem: problem description.

struct lsdn_problem_ref
#include <errors.h>

Reference to a problem item.

Consists of a problem type, and a pointer to a struct of the appropriate type.

Public Members

lsdn_problem_ref_type type

Problem type.

void* ptr

Pointer to the appropriate struct.

struct lsdn_problem
#include <errors.h>

Description of encountered problem.

Passed to a lsdn_problem_cb callback when an error occurs.

code refers to the type of problem encountered. Depending on the type of the problem, this might also indicate any number of related problematic items. Pointers to them are stored in refs.

Public Members

lsdn_problem_code code

Problem code.

size_t refs_count

Number of related items.

struct lsdn_problem_ref* refs

Array of references to related items.

Note
refs actually point to a buffer in lsdn_context.