| Kea 3.0.2-git

pkt_send_co.cc File Reference

Defines the pkt4_send and pkt6_send callout functions. More...

`#include <config.h>`
`#include <asiolink/io_address.h>`
`#include <hooks/hooks.h>`
`#include <dhcp/dhcp4.h>`
`#include <dhcp/dhcp6.h>`
`#include <dhcp/option_string.h>`
`#include <dhcp/option_custom.h>`
`#include <dhcp/option6_ia.h>`
`#include <dhcp/option6_iaaddr.h>`
`#include <dhcp/option6_iaprefix.h>`
`#include <dhcp/docsis3_option_defs.h>`
`#include <dhcp/pkt4.h>`
`#include <dhcp/pkt6.h>`
`#include <user_chk.h>`
Include dependency graph for pkt_send_co.cc:

Go to the source code of this file.

## Functions
void | add4Option (Pkt4Ptr &response, uint8_t opt_code, std::string &opt_value)
| Adds/updates are specific IPv4 string option in response packet.
void | add4Options (Pkt4Ptr &response, const UserPtr &user)
| Adds IPv4 options to the response packet based on given user.
void | add6Option (OptionPtr &vendor, uint8_t opt_code, std::string &opt_value)
| Adds/updates a specific IPv6 string vendor option.
void | add6Options (Pkt6Ptr &response, const UserPtr &user)
| Adds IPv6 vendor options to the response packet based on given user.
bool | checkIAStatus (boost::shared_ptr< Option6IA > &ia)
| Tests given IA option set for successful status.
void | generate_output_record (const std::string &id_type_str, const std::string &id_val_str, const std::string &addr_str, const bool &registered)
| Adds an entry to the end of the user check outcome file.
std::string | getAddrStrIA_NA (OptionPtr options)
| Stringify the lease address in an D6O_IA_NA option set.
std::string | getAddrStrIA_PD (OptionPtr options)
| Stringify the lease prefix in an D6O_IA_PD option set.
const UserPtr & | getDefaultUser4 ()
| Fetches the default IPv4 user from the registry.
const UserPtr & | getDefaultUser6 ()
| Fetches the default IPv6 user from the registry.
std::string | getV6AddrStr (Pkt6Ptr response)
| Stringify the lease address or prefix IPv6 response packet.
int | pkt4_send (CalloutHandle &handle)
| This callout is called at the "pkt4_send" hook.
int | pkt6_send (CalloutHandle &handle)
| This callout is called at the "pkt6_send" hook.

## Detailed Description

Defines the pkt4_send and pkt6_send callout functions.

Definition in file pkt_send_co.cc.

## Function Documentation

## ◆ add4Option()

void add4Option | ( | Pkt4Ptr & | response,
|  | uint8_t | opt_code,
|  | std::string & | opt_value )

Adds/updates are specific IPv4 string option in response packet.

Parameters

  response | IPV4 response packet to update
  opt_code | DHCP standard numeric code of the option
  opt_value | String value of the option

Definition at line 258 of file pkt_send_co.cc.

References isc::dhcp::Option::V4.

Referenced by add4Options().

## ◆ add4Options()

void add4Options | ( | Pkt4Ptr & | response,
|  | const UserPtr & | user )

Adds IPv4 options to the response packet based on given user.

Adds or replaces IPv4 options with values from the given user, if the user has corresponding properties defined. Currently it supports the following options:

- DHO_BOOT_FILE_NAME from user property "bootfile"
- DHO_TFTP_SERVER_NAME from user property "tftp_server"

Parameters

  response | IPv4 response packet
  user | User from whom properties are sourced

Definition at line 221 of file pkt_send_co.cc.

References add4Option(), isc::dhcp::DHO_BOOT_FILE_NAME, and isc::dhcp::DHO_TFTP_SERVER_NAME.

Referenced by pkt4_send().

Here is the call graph for this function:

## ◆ add6Option()

void add6Option | ( | OptionPtr & | vendor,
|  | uint8_t | opt_code,
|  | std::string & | opt_value )

Adds/updates a specific IPv6 string vendor option.

Parameters

  vendor | IPv6 vendor option set to update
  opt_code | DHCP standard numeric code of the option
  opt_value | String value of the option

Definition at line 321 of file pkt_send_co.cc.

References isc::dhcp::Option::V6.

Referenced by add6Options().

## ◆ add6Options()

void add6Options | ( | Pkt6Ptr & | response,
|  | const UserPtr & | user )

Adds IPv6 vendor options to the response packet based on given user.

Adds or replaces IPv6 vendor options with values from the given user, if the user has the corresponding properties defined. Currently it supports the following options:

- DOCSIS3_V6_CONFIG_FILE from user property "bootfile"
- DOCSIS3_V6_TFTP_SERVERS from user property "tftp_server"

Parameters

  response | IPv5 response packet
  user | User from whom properties are sourced

Todo
  : if packets have no vendor opt... do we need to add it if its not there? If so how?

Definition at line 282 of file pkt_send_co.cc.

References add6Option(), D6O_VENDOR_OPTS, DOCSIS3_V6_CONFIG_FILE, and DOCSIS3_V6_TFTP_SERVERS.

Referenced by pkt6_send().

Here is the call graph for this function:

## ◆ checkIAStatus()

bool checkIAStatus | ( | boost::shared_ptr< Option6IA > & | ia | ) |

Tests given IA option set for successful status.

This function is used to determine if the given Option6IA represents a successful lease operation. If it contains no status option or a status option of 0 (which is defined to mean success), then the option represents success and should contain a lease value (address or prefix).

Parameters

  ia | pointer to the Option6IA to test

Returns
  True if the option represents success, false otherwise.

Definition at line 515 of file pkt_send_co.cc.

References D6O_STATUS_CODE.

Referenced by getAddrStrIA_NA(), and getAddrStrIA_PD().

## ◆ generate_output_record()

void generate_output_record | ( | const std::string & | id_type_str,
|  | const std::string & | id_val_str,
|  | const std::string & | addr_str,
|  | const bool & | registered )

Adds an entry to the end of the user check outcome file.

Todo
  This ought to be replaced with an abstract output similar to UserDataSource to allow greater flexibility.

Each user entry is written in an ini-like format, with one name-value pair per line as follows:

id_type=<id type>
client=<id str>
subnet=<addr str>
registered=<is registered>

where: <id type> text label of the id type: "HW_ADDR" or "DUID" <id str> user's id formatted as either isc::dhcp::Hwaddr.toText() or isc::dhcp::DUID.toText() <addr str> selected subnet formatted as isc::dhcp::Subnet4::toText() or isc::dhcp::Subnet6::toText() as appropriate. <is registered> "yes" or "no"

Sample IPv4 entry would like this:

id_type=DUID
client=00:01:00:01:19:ef:e6:3b:00:0c:01:02:03:04
subnet=2001:db8:2::/64
registered=yes
id_type=duid
isc::dhcp::DUID
Holds DUID (DHCPv6 Unique Identifier).
Definition duid.h:142

Sample IPv4 entry would like this:

id_type=DUID
id_type=HW_ADDR
client=hwtype=1 00:0c:01:02:03:05
subnet=152.77.5.0/24
registered=no

Parameters

  id_type_str | text label identify the id type
  id_val_str | text representation of the user id
  addr_str | text representation of the selected subnet
  registered | boolean indicating if the user is registered or not

Definition at line 373 of file pkt_send_co.cc.

References user_chk_output.

Referenced by pkt4_send(), and pkt6_send().

## ◆ getAddrStrIA_NA()

std::string getAddrStrIA_NA | ( | OptionPtr | options | ) |

Stringify the lease address in an D6O_IA_NA option set.

Converts the IA_NA lease address into a string suitable for the user check outcome output.

Parameters

  options | pointer to the Option6IA instance from which to extract the lease address.

Returns
  A string containing the lease address.

Exceptions

  isc::BadValue | if the lease address cannot be extracted from options.

Definition at line 428 of file pkt_send_co.cc.

References checkIAStatus(), D6O_IAADDR, isc_throw, and isc::asiolink::IOAddress::toText().

Referenced by getV6AddrStr().

Here is the call graph for this function:

## ◆ getAddrStrIA_PD()

std::string getAddrStrIA_PD | ( | OptionPtr | options | ) |

Stringify the lease prefix in an D6O_IA_PD option set.

Converts the IA_PD lease prefix into a string suitable for the user check outcome output.

Parameters

  options | pointer to the Option6IA instance from which to extract the lease prefix.

Returns
  A string containing lease prefix

Exceptions

  isc::BadValue | if the prefix cannot be extracted from options.

Definition at line 467 of file pkt_send_co.cc.

References checkIAStatus(), D6O_IAPREFIX, isc_throw, and isc::asiolink::IOAddress::toText().

Referenced by getV6AddrStr().

Here is the call graph for this function:

## ◆ getDefaultUser4()

const UserPtr & getDefaultUser4 | ( |  | ) |

Fetches the default IPv4 user from the registry.

The default user may be used to provide default property values.

Returns
  A pointer to the IPv4 user or null if not defined.

Definition at line 538 of file pkt_send_co.cc.

References default_user4_id_str, user_chk::UserId::HW_ADDRESS, and user_registry.

Referenced by pkt4_send().

## ◆ getDefaultUser6()

const UserPtr & getDefaultUser6 | ( |  | ) |

Fetches the default IPv6 user from the registry.

The default user may be used to provide default property values.

Returns
  A pointer to the IPv6 user or null if not defined.

Definition at line 548 of file pkt_send_co.cc.

References default_user6_id_str, user_chk::UserId::DUID, and user_registry.

Referenced by pkt6_send().

## ◆ getV6AddrStr()

std::string getV6AddrStr | ( | Pkt6Ptr | response | ) |

Stringify the lease address or prefix IPv6 response packet.

Converts the lease value, either an address or a prefix, into a string suitable for the user check outcome output. Note that this will use the first address or prefix in the response for responses with more than one value.

Parameters

  response | IPv6 response packet from which to extract the lease value.

Returns
  A string containing the lease value.

Exceptions

  isc::BadValue | if the response contains neither an IA_NA nor IA_PD option.

Definition at line 402 of file pkt_send_co.cc.

References D6O_IA_NA, D6O_IA_PD, getAddrStrIA_NA(), getAddrStrIA_PD(), and isc_throw.

Referenced by pkt6_send().

Here is the call graph for this function:

## ◆ pkt4_send()

int pkt4_send | ( | CalloutHandle & | handle | ) |

This callout is called at the "pkt4_send" hook.

This function generates the user check outcome and modifies options to the IPv4 response packet based on whether the user is registered or not.

It retrieves a pointer to the registered user from the callout context. This value should have been set upstream. If the registered user pointer is non-null (i.e the user is registered), then a registered user outcome is recorded in the outcome output and the vendor properties are altered based upon this user's properties.

A null value means the user is not registered and a unregistered user outcome is recorded in the outcome output and the vendor properties are altered based upon the default IPv4 user in the registry (if defined).

Parameters

  handle | CalloutHandle which provides access to context.

Returns
  0 upon success, non-zero otherwise.

Definition at line 69 of file pkt_send_co.cc.

References add4Options(), isc::dhcp::DHCPNAK, generate_output_record(), isc::hooks::CalloutHandle::getArgument(), isc::hooks::CalloutHandle::getContext(), getDefaultUser4(), isc::hooks::CalloutHandle::getStatus(), user_chk::UserId::HW_ADDRESS_STR, isc_throw, CalloutHandle::NEXT_STEP_DROP, CalloutHandle::NEXT_STEP_SKIP, query_user_id_label, registered_user_label, and isc::asiolink::IOAddress::toText().

Here is the call graph for this function:

## ◆ pkt6_send()

int pkt6_send | ( | CalloutHandle & | handle | ) |

This callout is called at the "pkt6_send" hook.

This function generates the user check outcome and modifies options to the IPv6 response packet based on whether the user is registered or not.

It retrieves a pointer to the registered user from the callout context. This value should have been set upstream. If the registered user pointer is non-null (i.e the user is registered), then a registered user outcome is recorded in the outcome output and the vendor properties are altered based upon this user's properties.

A null value means the user is not registered and a unregistered user outcome is recorded in the outcome output and the vendor properties are altered based upon the default IPv6 user in the registry (if defined).

Parameters

  handle | CalloutHandle which provides access to context.

Returns
  0 upon success, non-zero otherwise.

Definition at line 149 of file pkt_send_co.cc.

References add6Options(), user_chk::UserId::DUID_STR, generate_output_record(), isc::hooks::CalloutHandle::getArgument(), isc::hooks::CalloutHandle::getContext(), getDefaultUser6(), isc::hooks::CalloutHandle::getStatus(), getV6AddrStr(), isc_throw, CalloutHandle::NEXT_STEP_DROP, CalloutHandle::NEXT_STEP_SKIP, query_user_id_label, and registered_user_label.

Here is the call graph for this function: