Ejemplo n.º 1
0
/**
 * @brief Create new option
 *
 * @param mf                    module helper functions
 * @param mi                    module instance information
 *
 * @return Returns RAT_ERROR on error, RAT_OK otherwise
 */
static int rat_opt_mtu_create (struct rat_mod_functions *mf,
                               struct rat_mod_instance *mi)
{
    struct rat_opt_mtu_private *mtu;
    RAT_DEBUG_TRACE();
    RAT_DISCARD_UNUSED(mf);

    /* allocate memory for module private data */
    mtu = calloc(1, sizeof(*mtu));
    if (!mtu) {
        rat_log_err("Module MTU: Out of memory!");
        goto exit_err;
    }

    /* set default values */
    mtu->mtu_enabled    = 0;
    mtu->mtu_autodetect = RAT_OPT_MTU_AUTO_DEF;
    mtu->mtu_linkmtu    = RAT_OPT_MTU_DEF;

    /* write back changes */
    RAT_MOD_PRIVATE(mi) = mtu;

    return RAT_OK;

exit_err:
    return RAT_ERROR;
}
Ejemplo n.º 2
0
/**
 * @brief Compile option
 *
 * @param mi                    module instance information
 *
 * @return Returns RAT_ERROR on error, RAT_OK otherwise
 */
static int rat_opt_mtu_compile (struct rat_mod_instance *mi)
{
    struct rat_opt_mtu_private *mtu = RAT_MOD_PRIVATE(mi);
    struct nd_opt_mtu *raw = RAT_MOD_RAWDATA(mi);
    RAT_DEBUG_TRACE();

    if (!mtu->mtu_enabled)
        goto exit_ok;

    /* allocate memory for raw data */
    if (!raw)
        raw = calloc(1, sizeof(*raw));
    if (!raw) {
        rat_log_err("Module MTU: Out of memory!");
        goto exit_err;
    }

    raw->nd_opt_mtu_type = ND_OPT_MTU;
    raw->nd_opt_mtu_len = 1;
    raw->nd_opt_mtu_reserved = 0;
    if (mtu->mtu_autodetect)
        raw->nd_opt_mtu_mtu = htonl(mi->mi_linkmtu);
    else
        raw->nd_opt_mtu_mtu = htonl(mtu->mtu_linkmtu);

    /* write back changes */
    RAT_MOD_RAWDATA(mi) = raw;
    RAT_MOD_RAWLEN(mi) = sizeof(*raw);

exit_ok:
    return RAT_OK;

exit_err:
    return RAT_ERROR;
}
Ejemplo n.º 3
0
/**
 * @brief Create new option
 *
 * @param mf                    module helper functions
 * @param mi                    module instance information
 *
 * @return Returns RAT_ERROR on error, RAT_OK otherwise
 */
static int rat_opt_cpuri_create (struct rat_mod_functions *mf,
                                 struct rat_mod_instance *mi)
{
    struct rat_opt_cpuri_private *cp;
    RAT_DEBUG_TRACE();
    RAT_DISCARD_UNUSED(mf);

    /* allocate memory for module private data */
    cp = calloc(1, sizeof(*cp));
    if (!cp) {
        rat_log_err("Module CPURI: Out of memory!");
        goto exit_err;
    }

    /* set default values */
    cp->cp_enabled = 0;

    /* write back changes */
    RAT_MOD_PRIVATE(mi) = cp;

    return RAT_OK;

exit_err:
    return RAT_ERROR;
}
Ejemplo n.º 4
0
Archivo: ra.c Proyecto: Rio/ratools
/**
 * @brief Create new RA
 *
 * @param mf                    module helper functions
 * @param mi                    module instance information
 *
 * @return Returns RAT_ERROR on error, RAT_OK otherwise
 */
static int rat_ra_create (struct rat_mod_functions *mf,
                          struct rat_mod_instance *mi)
{
    struct rat_ra_private *ra;
    RAT_DEBUG_TRACE();
    RAT_DISCARD_UNUSED(mf);

    /* allocate memory for module private data */
    ra = calloc(1, sizeof(*ra));
    if (!ra) {
        rat_log_err("Module RA: Out of memory!");
        goto exit_err;
    }

    /* set default values */
    ra->ra_curhl        = RAT_RA_CURHL_DEF;
    ra->ra_managed      = RAT_RA_MANAGED_DEF;
    ra->ra_other        = RAT_RA_OTHER_DEF;
    ra->ra_homeagent    = RAT_RA_HOMEAGENT_DEF;
    ra->ra_preference   = RAT_RA_PREFERENCE_DEF;
    ra->ra_proxy        = RAT_RA_PROXY_DEF;
    ra->ra_lifetime     = RAT_RA_LIFETIME_DEF;
    ra->ra_reachable    = RAT_RA_REACHABLE_DEF;
    ra->ra_retrans      = RAT_RA_RETRANS_DEF;

    /* write back changes */
    RAT_MOD_PRIVATE(mi) = ra;

    return RAT_OK;

exit_err:
    return RAT_ERROR;
}
Ejemplo n.º 5
0
/**
 * @brief Stores the forwarding state of an interface in the database
 *
 * @param db                    database entry
 *
 * @return Returns RAT_ERROR on error, RAT_OK otherwise
 */
int rat_prc_forwarding (struct rat_db *db)
{
    int f;
    FILE *fp;

    fp = fopen(RAT_PRC_IP6FORWARDPATH, "r");
    if (!fp) {
        rat_log_err("Could not open file `%s': %s", RAT_PRC_IP6FORWARDPATH,
                    strerror(errno));
        goto exit_err;
    }

    if (fscanf(fp, "%d", &f) != 1) {
        rat_log_err("Could read from file `%s': %s", RAT_PRC_IP6FORWARDPATH,
                    strerror(errno));
        goto exit_err;
    }
    fclose(fp);

    switch (f) {
        case RAT_PRC_FWD_DISABLED:
        case RAT_PRC_FWD_ENABLED:
        case RAT_PRC_FWD_ENABLEDRS:
            break;
        default:
            rat_log_wrn("Unknown value `%d' in file `%s'!", f,
                        RAT_PRC_IP6FORWARDPATH);
            rat_log_wrn("Assuming forwarding enabled.");
            break;
    }
    db->db_forwarding = f;

    return RAT_OK;

exit_err:
    return RAT_ERROR;
}
Ejemplo n.º 6
0
/**
 * @brief Compile option
 *
 * @param mi                    module instance information
 *
 * @return Returns RAT_ERROR on error, RAT_OK otherwise
 */
static int rat_opt_cpuri_compile (struct rat_mod_instance *mi)
{
    struct rat_opt_cpuri_private *cp = RAT_MOD_PRIVATE(mi);
    uint8_t *raw = RAT_MOD_RAWDATA(mi);
    uint16_t rawlen;
    RAT_DEBUG_TRACE();

    if (!cp->cp_enabled)
        goto exit_ok;

    rawlen = ALIGN(2 + MIN(strlen(cp->cp_uri), RAT_OPT_CPURI_URI_STRLEN), 8);

    /* allocate memory for raw data */
    if (!raw)
        raw = calloc(1, rawlen);
    if (!raw) {
        rat_log_err("Module CPURI: Out of memory!");
        goto exit_err;
    }

    raw[0] = RAT_OPT_CPURI_TYPE;
    raw[1] = rawlen / 8;

    memcpy(((uint8_t *) raw) + 2, &cp->cp_uri,
           MIN(strlen(cp->cp_uri), RAT_OPT_CPURI_URI_STRLEN));

    /* write back changes */
    RAT_MOD_RAWDATA(mi) = raw;
    RAT_MOD_RAWLEN(mi) = rawlen;

exit_ok:
    return RAT_OK;

exit_err:
    return RAT_ERROR;
}
Ejemplo n.º 7
0
Archivo: ra.c Proyecto: Rio/ratools
/**
 * @brief Compile RA
 *
 * @param mi                    module instance information
 *
 * @return Returns RAT_ERROR on error, RAT_OK otherwise
 */
static int rat_ra_compile (struct rat_mod_instance *mi)
{
    struct rat_ra_private *ra = RAT_MOD_PRIVATE(mi);
    struct nd_router_advert *nra = RAT_MOD_RAWDATA(mi);
    RAT_DEBUG_TRACE();

    /* allocate memory for raw data */
    if (!nra)
        nra = calloc(1, sizeof(*nra));
    if (!nra) {
        rat_log_err("Module RA: Out of memory!");
        goto exit_err;
    }

    nra->nd_ra_type = ND_ROUTER_ADVERT;
    nra->nd_ra_curhoplimit = ra->ra_curhl;
    if (ra->ra_managed)
        nra->nd_ra_flags_reserved |= ND_RA_FLAG_MANAGED;
    if (ra->ra_other)
        nra->nd_ra_flags_reserved |= ND_RA_FLAG_OTHER;
    if (ra->ra_homeagent)
        nra->nd_ra_flags_reserved |= ND_RA_FLAG_HOME_AGENT;
    switch (ra->ra_preference) {
        case RAT_RA_PREF_LOW:
            nra->nd_ra_flags_reserved |= ND_RA_RTPREF_LOW;
            break;
        case RAT_RA_PREF_MEDIUM:
            nra->nd_ra_flags_reserved |= ND_RA_RTPREF_MEDIUM;
            break;
        case RAT_RA_PREF_HIGH:
            nra->nd_ra_flags_reserved |= ND_RA_RTPREF_HIGH;
            break;
        case RAT_RA_PREF_RESERVED:
            nra->nd_ra_flags_reserved |= ND_RA_RTPREF_RESERVED;
            break;
        default:
            rat_log_err("Module RA: Could not compile RA header! " \
                        "Invalid router preference.");
            goto exit_err;
            break;
    }
    if (ra->ra_proxy)
        nra->nd_ra_flags_reserved |= ND_RA_FLAG_PROXY;

    nra->nd_ra_router_lifetime = htons(ra->ra_lifetime);
    nra->nd_ra_reachable = htonl(ra->ra_reachable);
    nra->nd_ra_retransmit = htonl(ra->ra_retrans);

    /*
     * In such cases the router SHOULD transmit one or more (but not more
     * than MAX_FINAL_RTR_ADVERTISEMENTS) final multicast Router
     * Advertisements on the interface with a Router Lifetime field of zero.
     *
     * (RFC 2461 Sec. 6.2.5. Ceasing To Be An Advertising Interface)
     */
    if (mi->mi_fadingout) {
        nra->nd_ra_router_lifetime = 0;
        /*
         * If the Router Lifetime is zero, the preference value MUST be set
         * to (00) by the sender and MUST be ignored by the receiver.
         *
         * (RFC 4191 sec. 2.2.)
         */
        ra->ra_preference = RAT_RA_PREF_MEDIUM;
    }

    /* write back changes */
    RAT_MOD_RAWDATA(mi) = nra;
    RAT_MOD_RAWLEN(mi) = sizeof(*nra);

    return RAT_OK;

exit_err:
    return RAT_ERROR;
}