• Andrea Mayer's avatar
    seg6: improve management of behavior attributes · 964adce5
    Andrea Mayer authored
    Depending on the attribute (i.e.: SEG6_LOCAL_SRH, SEG6_LOCAL_TABLE, etc),
    the parse() callback performs some validity checks on the provided input
    and updates the tunnel state (slwt) with the result of the parsing
    operation. However, an attribute may also need to reserve some additional
    resources (i.e.: memory or setting up an eBPF program) in the parse()
    callback to complete the parsing operation.
    
    The parse() callbacks are invoked by the parse_nla_action() for each
    attribute belonging to a specific behavior. Given a behavior with N
    attributes, if the parsing of the i-th attribute fails, the
    parse_nla_action() returns immediately with an error. Nonetheless, the
    resources acquired during the parsing of the i-1 attributes are not freed
    by the parse_nla_action().
    
    Attributes which acquire resources must release them *in an explicit way*
    in both the seg6_local_{build/destroy}_state(). However, adding a new
    attribute of this type requires changes to
    seg6_local_{build/destroy}_state() to release the resources correctly.
    
    The seg6local infrastructure still lacks a simple and structured way to
    release the resources acquired in the parse() operations.
    
    We introduced a new callback in the struct seg6_action_param named
    destroy(). This callback releases any resource which may have been acquired
    in the parse() counterpart. Each attribute may or may not implement the
    destroy() callback depending on whether it needs to free some acquired
    resources.
    
    The destroy() callback comes with several of advantages:
    
     1) we can have many attributes as we want for a given behavior with no
        need to explicitly free the taken resources;
    
     2) As in case of the seg6_local_build_state(), the
        seg6_local_destroy_state() does not need to handle the release of
        resources directly. Indeed, it calls the destroy_attrs() function which
        is in charge of calling the destroy() callback for every set attribute.
        We do not need to patch seg6_local_{build/destroy}_state() anymore as
        we add new attributes;
    
     3) the code is more readable and better structured. Indeed, all the
        information needed to handle a given attribute are contained in only
        one place;
    
     4) it facilitates the integration with new features introduced in further
        patches.
    Signed-off-by: default avatarAndrea Mayer <andrea.mayer@uniroma2.it>
    Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
    964adce5
seg6_local.c 25.3 KB