Changeset b2eb48c in rtems-libbsd


Ignore:
Timestamp:
05/02/18 07:01:32 (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
5, 5-freebsd-12, 6-freebsd-12, master
Children:
e1d62e8
Parents:
8bd38d6
git-author:
Sebastian Huber <sebastian.huber@…> (05/02/18 07:01:32)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/08/18 05:37:17)
Message:

dhcpcd: Add hooks

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • dhcpcd/dhcpcd.c

    r8bd38d6 rb2eb48c  
    16001600        exit(EXIT_SUCCESS);
    16011601}
     1602#ifdef __rtems__
     1603int
     1604dhcpcd_script_runreason_do_nothing(const struct interface *ifp,
     1605    const char *reason)
     1606{
     1607        return 0;
     1608}
     1609
     1610/*
     1611 * Do not pull in the script support if it is not used, e.g. no call to
     1612 * rtems_dhcpcd_add_hook() is present.
     1613 */
     1614__weak_reference(dhcpcd_script_runreason_do_nothing, dhcpcd_script_runreason);
     1615#endif /* __rtems__ */
  • dhcpcd/namespace.h

    r8bd38d6 rb2eb48c  
    157157#define read_config dhcpcd_read_config
    158158#define read_lease dhcpcd_read_lease
     159#define script_runreason dhcpcd_script_runreason
    159160#define select_profile dhcpcd_select_profile
    160161#define set_cloexec dhcpcd_set_cloexec
  • dhcpcd/script.c

    r8bd38d6 rb2eb48c  
    5252#include "net.h"
    5353#include "script.h"
    54 
     54#ifdef __rtems__
     55#include <rtems/dhcpcd.h>
     56
     57static SLIST_HEAD(, rtems_dhcpcd_hook) dhcpcd_hooks =
     58  SLIST_HEAD_INITIALIZER(dhcpcd_hooks);
     59
     60void
     61rtems_dhcpcd_add_hook(rtems_dhcpcd_hook *hook)
     62{
     63        rtems_recursive_mutex_lock(&dhcpcd_mutex);
     64        SLIST_INSERT_HEAD(&dhcpcd_hooks, hook, node);
     65        rtems_recursive_mutex_unlock(&dhcpcd_mutex);
     66}
     67
     68void
     69rtems_dhcpcd_remove_hook(rtems_dhcpcd_hook *hook)
     70{
     71        rtems_recursive_mutex_lock(&dhcpcd_mutex);
     72        SLIST_REMOVE(&dhcpcd_hooks, hook, rtems_dhcpcd_hook, node);
     73        rtems_recursive_mutex_unlock(&dhcpcd_mutex);
     74}
     75#endif /* __rtems__ */
     76
     77#ifndef __rtems__
    5578#define DEFAULT_PATH    "PATH=/usr/bin:/usr/sbin:/bin:/sbin"
    5679
     
    105128        return pid;
    106129}
     130#endif /* __rtems__ */
    107131
    108132#ifdef INET
     
    169193#endif
    170194
     195#ifndef __rtems__
    171196static size_t
    172197arraytostr(const char *const *argv, char **s)
     
    192217        return len;
    193218}
     219#endif /* __rtems__ */
    194220
    195221static ssize_t
     
    436462}
    437463
     464#ifndef __rtems__
    438465static int
    439466send_interface1(int fd, const struct interface *iface, const char *reason)
     
    508535        return retval;
    509536}
     537#endif /* __rtems__ */
    510538
    511539int
    512540script_runreason(const struct interface *ifp, const char *reason)
    513541{
     542#ifndef __rtems__
    514543        char *const argv[2] = { UNCONST(ifp->options->script), NULL };
     544#endif /* __rtems__ */
    515545        char **env = NULL, **ep;
     546#ifndef __rtems__
    516547        char *path, *bigenv;
    517548        ssize_t e, elen = 0;
    518549        pid_t pid;
     550#else /* __rtems__ */
     551        ssize_t elen;
     552        rtems_dhcpcd_hook *hook;
     553        rtems_dhcpcd_hook *hook2;
     554#endif /* __rtems__ */
    519555        int status = 0;
     556#ifndef __rtems__
    520557        const struct fd_list *fd;
    521558        struct iovec iov[2];
     559#endif /* __rtems__ */
    522560
    523561        if (ifp->options->script == NULL ||
     
    526564                return 0;
    527565
     566#ifndef __rtems__
    528567        syslog(LOG_DEBUG, "%s: executing `%s' %s",
    529568            ifp->name, argv[0], reason);
     569#endif /* __rtems__ */
    530570
    531571        /* Make our env */
    532572        elen = make_env(ifp, reason, &env);
     573#ifndef __rtems__
    533574        ep = realloc(env, sizeof(char *) * (elen + 2));
    534575        if (ep == NULL) {
     
    597638
    598639out:
     640#else /* __rtems__ */
     641        rtems_recursive_mutex_lock(&dhcpcd_mutex);
     642
     643        SLIST_FOREACH_SAFE(hook, &dhcpcd_hooks, node, hook2) {
     644                syslog(LOG_DEBUG, "%s: executing `%s' %s", ifp->name,
     645                    hook->name, reason);
     646                (*hook->handler)(hook, env);
     647        }
     648
     649        rtems_recursive_mutex_unlock(&dhcpcd_mutex);
     650#endif /* __rtems__ */
    599651        /* Cleanup */
    600652        ep = env;
  • dhcpcd/script.h

    r8bd38d6 rb2eb48c  
    3434#ifndef __rtems__
    3535int send_interface(int, const struct interface *);
    36 int script_runreason(const struct interface *, const char *);
    3736#else /* __rtems__ */
    3837static inline int send_interface(int fd, const struct interface *iface)
     
    4039        return 0;
    4140}
    42 static inline int script_runreason(const struct interface *ifp, const char *reason)
    43 {
    44         return 0;
    45 }
    4641#endif /* __rtems__ */
     42int script_runreason(const struct interface *, const char *);
    4743
    4844#endif
  • libbsd.py

    r8bd38d6 rb2eb48c  
    45544554                'dhcpcd/net.c',
    45554555                'dhcpcd/platform-bsd.c',
     4556                'dhcpcd/script.c',
    45564557                'dhcpcd/compat/pselect.c',
    45574558                'dhcpcd/crypt/hmac_md5.c',
  • rtemsbsd/include/rtems/dhcpcd.h

    r8bd38d6 rb2eb48c  
    4141#define _RTEMS_DHCPCD_H_
    4242
     43#include <sys/cdefs.h>
     44#include <sys/queue.h>
     45
    4346#include <rtems.h>
    4447
     
    7679rtems_status_code rtems_dhcpcd_start(const rtems_dhcpcd_config *config);
    7780
     81typedef struct rtems_dhcpcd_hook {
     82        SLIST_ENTRY(rtems_dhcpcd_hook) node;
     83        const char *name;
     84        void (*handler)(struct rtems_dhcpcd_hook *hook, char *const *env);
     85} rtems_dhcpcd_hook;
     86
     87/**
     88 * @brief Adds a DHCP client hook.
     89 *
     90 * The hook handler is invoked with an environment list (NULL terminated) of
     91 * strings ('\0' terminated).  Each string of the environment list has usually
     92 * the format "key=value", e.g. "interface=eth0", "reason=BOUND".
     93 *
     94 * The hook handler are called by the DHCP client task.  It is safe to
     95 * add/remove hooks in the hook handler.
     96 */
     97void rtems_dhcpcd_add_hook(rtems_dhcpcd_hook *hook);
     98
     99/**
     100 * @brief Removes a DHCP client hook.
     101 */
     102void rtems_dhcpcd_remove_hook(rtems_dhcpcd_hook *hook);
     103
    78104/** @} */
    79105
  • testsuite/dhcpcd01/test_main.c

    r8bd38d6 rb2eb48c  
    11/*
    2  * Copyright (c) 2013-2014 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2013, 2018 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    3131
    3232#include <assert.h>
     33#include <stdio.h>
    3334
    3435#include <rtems.h>
     36#include <rtems/dhcpcd.h>
    3537
    3638#define TEST_NAME "LIBBSD DHCPCD 1"
    3739
    3840static void
     41dhcpcd_hook_handler(rtems_dhcpcd_hook *hook, char *const *env)
     42{
     43
     44        (void)hook;
     45
     46        while (*env != NULL) {
     47                printf("%s\n", *env);
     48                ++env;
     49        }
     50}
     51
     52static rtems_dhcpcd_hook dhcpcd_hook = {
     53        .name = "test",
     54        .handler = dhcpcd_hook_handler
     55};
     56
     57static void
    3958test_main(void)
    4059{
     60
     61        rtems_dhcpcd_add_hook(&dhcpcd_hook);
     62
    4163        rtems_task_delete(RTEMS_SELF);
    4264        assert(0);
Note: See TracChangeset for help on using the changeset viewer.