⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipripng_daemon.c

📁 这是最新的vxWorks6.7协议栈下的RIPng(rip over ipv6)实现
💻 C
📖 第 1 页 / 共 2 页
字号:
    /***** Initialize IPRIPng. *****/    ret = ipripng_init();    if(ret != IPCOM_SUCCESS)    {        IPCOM_LOG1(ERR, "ipripngd :: ipripng_init() failed, err = %ld", ret);        goto badout;    }    ipripng_init_ok = IP_TRUE;    /* Open udp and routing sockets */    ret = ipripng_initsocks();    if (ret != IPCOM_SUCCESS) {        IPCOM_LOG1(ERR, "ipripngd :: ipripng_initsocks() failed, err = %ld", ret);        goto badout;    }    udp_fd = ipripng_ripsocket();    rt_fd = ipripng_rtsocket();    /***** Open and configure IPRIPNG. *****/    conf.ripng_write = ipripng_write;    conf.add_route = ipripng_add_route_rtsock;    conf.delete_route = ipripng_delete_route_rtsock;    conf.conf[0] = IP_TAG_END;    ret = ipripng_open(&conf);    if(ret != IPCOM_SUCCESS) {        IPCOM_LOG1(ERR, "ipripngd :: ipripng_open() failed, err = %ld", ret);        goto badout;    }    ipripng_open_ok = IP_TRUE;    /* Initialize RIPng interfaces */    /* Check ripngStop() wasn't called as below can sleep */    if ((ipripng_ifconfig() != IPCOM_SUCCESS) || ripngStopFlag) {        IPCOM_LOG1(ERR, "ipripngd :: ipripng_ifconfig() failed, err = %ld", ret);        goto badout;    }    /* Add interface routes */    for (ifcp = ipripng_ifhead(); ifcp; ifcp = ifcp->ifc_next)        if (ipripng_ifrt(ifcp, 0) < 0) {            IPCOM_LOG0(ERR, "ipripngd :: ipripng_ifrt() failed");            goto badout;        }    /* Process -A and -O filter options */    if (ipripng_filterconfig() != IPCOM_SUCCESS) {        IPCOM_LOG0(ERR, "ipripngd :: ipripng_filterconfig() failed");        goto badout;    }    /* Add kernel routes */    if (ipripng_krtread(0) != IPCOM_SUCCESS) {        IPCOM_LOG0(ERR, "ipripngd :: ipripng_krtread() failed");        goto badout;    }    /* IPD init. */    if(ipcom_ipd_init("ipripng", IPCOM_SUCCESS, &ipd_fd) != IPCOM_SUCCESS) {        ipcom_printf("ipripngd :: ipcom_ipd_init() failed");        goto badout;    }    /* Send the initial request to RIPng interfaces */    for (ifcp = ipripng_ifhead(); ifcp; ifcp = ifcp->ifc_next) {        if (iff_find(ifcp, 'N'))                continue;        if (ifcp->ifc_index > 0 && (ifcp->ifc_flags & IP_IFF_UP) &&            ((ifcp->ifc_flags & IP_IFF_LOOPBACK) == 0))            {            ipripng_sendrequest(ifcp);            }    }    /***** Input loop. *****/    max = IP_MAX(udp_fd, rt_fd);    max = IP_MAX(max, ipd_fd);    IP_FD_ZERO(&fds);    IP_FD_SET(udp_fd, &fds);    IP_FD_SET(rt_fd,  &fds);    IP_FD_SET(ipd_fd, &fds);    /* set the timeout value */    memset(&tv, 0, sizeof(struct Ip_timeval));    tv.tv_sec = 1;    tv.tv_usec = 0;    ptv = &tv;    IPCOM_LOG0(INFO, "**** Started ****");    while (1) {        /* Check ripngStop() wasn't called */        if (ripngStopFlag) {            IPCOM_LOG0(INFO, "RIPng requested to close. Closing down");            goto badout;        }        read_set = fds;        num = ipcom_socketselect(max + 1, &read_set, IP_NULL, IP_NULL, ptv);        if (ripngStopFlag) {            IPCOM_LOG0(INFO, "RIPng requested to close. Closing down");            goto badout;        }        switch (num) {            case -1:                IPCOM_LOG0(ERR, "ipripngd select error");                goto badout;                continue;            case 0:                continue;            default:                if (IP_FD_ISSET(udp_fd, &read_set)) {                    IPCOM_LOG0 (INFO, "RIPng message received");                    if (ipripng_riprecv() != IPCOM_SUCCESS) {                        goto badout;                    }                }                if (IP_FD_ISSET(rt_fd, &read_set)) {                    IPCOM_LOG0(INFO, "Message received on routing socket");                    if (ipripng_rtrecv() != IPCOM_SUCCESS) {                        goto badout;                    }                }                if (IP_FD_ISSET(ipd_fd, &read_set)) {                    int event;                    event = ipcom_ipd_input(ipd_fd);                    switch(event) {                        case IPCOM_IPD_EVENT_KILL:                            IPCOM_LOG0(INFO, "received IPD kill message");                            goto badout;                        default:                            break;                    }                }        } /* switch */    } /* while */badout:    if(ipd_fd == IP_INVALID_SOCKET)        (void)ipcom_ipd_init("ipripng", IPCOM_ERR_FAILED, &ipd_fd);    if(ipripng_open_ok)        (void)ipripng_close();    if(ipripng_init_ok)        (void)ipripng_exit();    (void)ipcom_ipd_exit("ipripng", ipd_fd);    IPCOM_LOG0(INFO, "ipripngd :: ending");    ipcom_proc_exit();}/* **************************************************************************** * 10                    PUBLIC FUNCTIONS **************************************************************************** *//* *=========================================================================== *                    ipripng_create *=========================================================================== * Description: * Parameters: * Returns: * */IP_PUBLIC Ip_erripripng_create(void){    return IPCOM_SUCCESS;}/********************************************************************************* ripngStart - Start the RIPng system** This routine starts the RIPng routing daemon which supports RIPng over IPv6.** <cmdString> is a string that can contain a selection of parameters as follows:*** -a         Enables aging of the statically defined routes. With this option,*            any statically defined routes will be removed unless corresponding*            updates arrive as if the routes are received at startup.** -A prefix/preflen,if1[,if2...]*            This option is used for aggregating routes. prefix/preflen specifies*            the prefix and the prefix length of the aggregated route. When*            advertising routes, RIPng filters specific routes covered by the*            aggregate, and advertises the aggregated route prefix/preflen, to*            the interfaces specified in the comma-separated interface list,*            if1[,if2...]. RIPng creates a static route to prefix/preflen with*            RTF_REJECT flag, into the kernel routing table.** -d         Enables output of debugging messages.** -D         Enables extensive output of debugging messages.** -h         Disable split horizon processing by default. Unless interfaces are*            explicitly configured using -x/y/z, all new interfaces have Split*            Horizon with Poison Reverse enabled. We can use -h to disable*            this so that all new interfaces have Split Horizon disabled.*            See also -p which causes all new interfaces to default to Split*            Horizon without Poison Reverse. Do not specify -p or -h if you wish*            to default all new interfaces to Poison Reverse.** -l         Exchange site local routes. By default, RIPng will not exchange*            site local routes for safety reasons. This is because semantics of*            site local address space is rather vague (specification is still*            being worked on), and there is no good way to define site local*            boundary. With -l option, RIPng will exchange site local routes as*            well. It must not be used on site boundary routers, since -l option*            assumes that all interfaces are in the same site.** -L prefix/preflen,if1[,if2...]*            Filter incoming routes from interfaces if1,[if2...]. RIPng will*            accept incoming routes that are in prefix/preflen. If multiple -L*            options are specified, any routes that match one of the options is*            accepted. ::/0 is treated specially as default route, not "any*            route that has longer prefix length than, or equal to 0". If you would*            like to accept any route, specify no -L option. For example, with*            "-L 3ffe::/16,if1 -L ::/0,if1". RIPng will accept default route and*            routes in 6bone test address, but no others.** -N if1[,if2...]*            Do not listen to, or advertise, route from/to interfaces specified by*            if1,[if2...].** -O prefix/preflen,if1[,if2...]*            Restrict route advertisement toward interfaces specified by*            if1,[if2...]. With this option RIPng will only advertise routes that*            matches prefix/preflen.** -p         Disable Poison Reverse by default. Specifying this causes all new*            interfaces to use Split Horizon without Poison Reverse. To disable*            Split Horizon altogether use -h. Note that this does not affect*            interfaces which are explicitly configured using -x/y/z. -p and -h*            are only used to set the default mode for interfaces which are not*            explicitly configured. To use Poison Reverse by default, do not*            specify either -p or -h.** -q         Puts RIPng in listen only mode. No advertisements are sent.** -r addr1[,addr2...]*            Restricted Neighbor List. Only accept responses from the routers*            specified in the address list (addr1...).** -s         Makes RIPng advertise the statically defined routes which exist in the*            kernel routing table when RIPng invoked. Announcements obey the regular*            split horizon rule.** -S         This option is the same as -s option except that no split horizon rule*            is applied.** -T if1[,if2...]*            Advertise only default route, toward if1,[if2...].** -t tag*            Attach route tag tag to originated route entries. tag can be decimal,*            octal prefixed by 0, or hexadecimal prefixed by 0x.** -x if1[,if2...]*            Enable Poison Reverse Processing for these interfaces.** -y if1[,if2...]*            Enable Split Horizon (without Poison Reverse) for these interfaces.** -z if1[,if2...]*            Disable Split Horizon altogether on these interfaces.*** <priority> specifies the priority of the main RIPng task: tRipTask. Specifying* no priority (0) uses the default priority of 100. Note that the RIPng task* priorities must be lower (worse) than tNetTask's priority.** It may be called from the VxWorks shell as follows:** .CS* -> ripngStart "[options]", [pri]* .CE** Or to accept the default priority:** .CS* -> ripngStart "[options]"* .CE** A supporting task (tRipDog) is always created with a higher priority than* tRipTask. It's priority is equal to ((priority of tRipTask) - 1).** RETURNS: N/A** ERRNO: ENOMEM, EALREADY**/IP_PUBLIC Ip_err ripngStart    (    char *  cmdString,  /* String of options */    int     priority    /* Required priority level for tRipngTask */    ){    Ip_err  ret = IPCOM_SUCCESS;    Ipcom_proc_attr  attr;    if(priority==0 || priority > IPCOM_PRIORITY_MAX)        priority = IPCOM_PRIORITY_DEFAULT - 1;    /* Check not already running */    if (daemon_started == IP_TRUE) {        IPCOM_LOG0(ERR, "ripngStart: RIPng already running");        return IPCOM_ERR_ALREADY_STARTED;    }    ipcom_proc_attr_init(&attr);    attr.priority = priority;    attr.stacksize = RIPTASKSTACK;    ipcom_strcpy(ripng_cmdString, " ");    ipcom_strcpy(ripng_cmdString, cmdString);    ret = ipcom_proc_acreate(RIPTASKNAME, ipripngd, &attr, IP_NULL);    if (ret != IPCOM_SUCCESS) {        IPCOM_LOG0(ERR, "ripngStart: Failed on ipcom_proc_acreate");    }   return ret;}/********************************************************************************* ripngStop - Stop the RIPng system** This routine stops the RIPng routing daemon.** It may be used to reconfigure RIPng by stopping it and restarting with* ripngStart() and different parameters.** It may be called from the VxWorks shell as follows:** .CS* -> ripngStop* .CE** RETURNS: N/A** ERRNO:**/void ripngStop (void){    /* Check whether RIPng already running */    if (daemon_started == IP_FALSE) {        IPCOM_LOG0(ERR, "ripngStop: RIPng not started yet");        return;    }    ripngStopFlag = IP_TRUE;    daemon_started = IP_FALSE;    return;}/* *=========================================================================== *                    ipripng_start *=========================================================================== * Description: * Parameters: * Returns: * */IP_PUBLIC Ip_erripripng_start(void){    Ip_err  ret;    Ipcom_proc_attr  attr;    ipcom_proc_attr_init(&attr);    attr.priority = IPCOM_PRIORITY_DEFAULT - 1;    ret = ipcom_proc_acreate(RIPTASKNAME, ipripngd, &attr, IP_NULL);    ip_assert(ret == IPCOM_SUCCESS);    return ret;}/* **************************************************************************** *                      END OF FILE **************************************************************************** */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -