Adding a Route or Next Hop

An entry that describes a route must include the following information:

When a configuration containing a new route and next hop is committed, an application calls DDL Access (DAX) functions to read the configuration and adds the values to the configuration database. The sample application reads the configuration in the config_read() and config_rt_read() functions in route-manager_config.c, and adds the configuration values to the database in the config_rt_add() and config_nh_add() functions.

Setting Route Parameters and Adding the Route on the Server

Once the route configuration has been successfully added to the configuration database, the sample application adds the route on the server by calling the function ssd_rt_add() in route-manager_ssd.c, from the config_rt_add() function.

The ssd_request_route_add() function requires details about the route, which you supply in an ssd_route_parms structure:

int ssd_request_route_add (int fd, struct ssd_route_parms *rtp,
                              unsigned int client_ctx);

The parameters are declared as follows in the header file ssd_ipc_msg.h:

struct ssd_route_parms {
         ssd_sockaddr_un  *rta_dest;                /* Route address */
         u_int16_t         rta_prefixlen;           /* Prefix length */
         u_int16_t         rta_state;               /* State */
         u_int32_t         rta_gw_handle;           /* Gateway handle */
         struct ssd_rt_metrics rta_metrics;         /* Metrics */
         struct ssd_rt_metrics rta_preferences;     /* Preferences */
         ssd_rt_tableid    rta_rtt;                 /* Routing table */
         u_int16_t         rta_flags;               /* Flags */
         u_int8_t          rta_nhtype;              /* Next hop type */
         u_int8_t          rta_n_gw;                /* Number of gateways */
         struct ssd_rt_gateway rta_gateway[SSD_ROUTE_N_MULTIPATH]; /* The gateways */                                                                        gateways */
     };

The application assigns values before passing the information to ssd_request_route_add() as shown in the following code. Once all the required parameter values are present, you call ssd_request_route_add() to send the request.

int
ssd_rt_add (route_t *rt)
{
    struct ssd_route_parms params;
    int i;

    bzero(&params, sizeof(params));
    params.rta_dest = &rt->dst_addr;
    params.rta_prefixlen = rt->prefix_len;
    params.rta_rtt = nh_pool[rt->rtt_id].idx;
    params.rta_nhtype = rt->nh_type;
    params.rta_state = rt->op_state;
    params.rta_flags = rt->flag;
    params.rta_preferences.rtm_val[0] = rt->preference;
    params.rta_preferences.rtm_type[0] = SSD_RTM_VALUE_PRESENT;
    params.rta_n_gw = rt->gw_num;
    for (i = 0; i < rt->gw_num; i++) {
        if (rt->gw_addr[i].in.gin_family == SSD_GF_INET) {
            params.rta_gateway[i].rtg_gwaddr = &rt->gw_addr[i];
        }
        if (rt->gw_ifl_addr[i].in.gin_family == SSD_GF_INET) {
            params.rta_gateway[i].rtg_lcladdr = &rt->gw_ifl_addr[i];
        }
        if (rt->gw_ifl_name[i][0] != '\0') {
            params.rta_gateway[i].rtg_iflname = rt->gw_ifl_name[i];
        }
        ifl_idx_t_setval(params.rta_gateway[i].rtg_ifl, rt->gw_ifl_idx);
        nh_idx_t_setval(params.rta_gateway[i].rtg_nhindex,
                nh_pool[rt->nh_id[i]].idx);
        RM_TRACE(TF_SSD, "%s: %d, %d, %d, %d, %d", __func__,
                rt->gw_addr[i].in.gin_family,
                rt->gw_ifl_addr[i].in.gin_family,
                rt->gw_ifl_name[i][0],
                rt->gw_ifl_idx,
                nh_pool[rt->nh_id[i]].idx);

    }
    if (ssd_request_route_add(ssd_fd, &params, (unsigned int)rt) < 0) {
        return -1;
    } else {
        return 0;
    }
}

The values were obtained as follows:

The additional information is retrieved from the configuration using DAX calls. The sample application does this in the config_rt_read() function in route-manager_config.c.

Using a Next-Hop Table

You can add a next hop that is itself a table. The following code in ssd_nh_add() checks the SSD_RNH_TABLE flag to do this (SSD_RNH_SERVICE indicates a next hop that is one route):

switch (rt->nh_type) {
    case SSD_RNH_SERVICE:
        bzero(&params, sizeof(params));
        ifl_idx = kcom_ifl_get_idx_by_name(nh_pool[nh_id].name);
        if (ifl_idx < 0) {
            return -1;
        }
        ifl_idx_t_setval(params.ifl, ifl_idx);
        rc = ssd_request_nexthop_add(ssd_fd, nh_id, &params, (unsigned int)rt);
        break;
    case SSD_RNH_TABLE:
        name = strdup(nh_pool[nh_id].name);
        rc = ssd_request_route_table_lookup(ssd_fd, name, (unsigned int)rt);
        break;
    default:
        rc = -1;
    }
    return rc;

For additional usage information on next-hop tables, see Directing Traffic to a Different Routing Table.

Deleting a Route


2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:26:47 2010 for Juniper Networks Partner Solution Development Platform JUNOS SDK 10.2R1 by Doxygen 1.4.5