Error: Net-snmp/net-snmp-features.h: no file or directory

Source: Internet
Author: User
Tags snmp perl script dtls

Requires NET-SNMP 5.7

Note:features discussed on this page require NET-SNMP version 5.7 or higher.

Note:features discussed on this page require NET-SNMP version 5.7 or higher.

Contents
  • 1 Background
    • 1.1 Results
  • 2 Design Criteria
  • 3 feature marking and requiring Macros
    • 3.1 Parent/child Features
    • 3.2 conditionally requiring and providing Features
      • 3.2.1 providing a feature only if possible
      • 3.2.2 checking whether or not another Feature is required
      • 3.2.3 checking whether or not a dependent feature is available
  • 4 Coding Using Features Support
    • 4.1 Checking for Feature support in Code
  • 5 Behind the Scenes
  • 6 Notes on the end result
  • 7 Real World Examples
    • 7.1 Tls/dtls
  • 8 finding Unused Code to Mark as a Feature
Background

Many components of NET-SNMP is present to support certain features in the code. But if the code that requires a feature isn't compiled in, the supporting code still are and needlessly adds to the size of The running executable and libraries.

Results

The current SVN trunk contains code, marked as described in this document. The resulting feature hierarchy can be found on the Features page.

Design Criteria
    • By default, everything must still is included. 3rd-party developers May is making use of code even if internal NET-SNMP code isn ' t.
    • A Configure flag (--with-minimalist) to enable minimal code
      • --enable-mini-agent should probably turn it on?
    • Flags to request including and excluding of features
      • --with-features= "Foo Bar"
      • --with-out-features= "Foo Bar"
Feature marking and requiring Macros

To-start with, include <net-snmp/features.h>

#include <net-snmp/features.h>

If you ' re implementing code it is only needed in certain locations, declare the feature name using the Netsnmp_featu Re_provide () macro:

Netsnmp_feature_provide (foo)

If the feature is dependent on the availability of another feature, use the netsnmp_feature_require () or nets Nmp_feature_want () macros:

Netsnmp_feature_require (foo) netsnmp_feature_want (bar)

If foo is unavailable a hard-error would be triggered. However, if bar is unavailable the compilation would continue.

Parent/child Features

To mark a child as being a sub-feature of a parent, use the following macro:

Netsnmp_feature_child_of (child,parent)

This would:

    1. If the child is required:
      • Would turn on the child
      • Won't turn on the parent
    2. If the parent is required:
      • Would turn on the child
      • Would turn on the parent

conditionally requiring and providing Features

The feature macros is checked in the output of CPP processing, so typical #ifdef macros can is used to conditionally incl Ude or provide features.

providing a feature only if possible

To provide conditional support of a feature depending on the output of configure checks:

#include <net-snmp/net-snmp-config.h> #include <net-snmp/features.h>  #ifdef have_foo_h netsnmp_ Feature_provide (Netsnmpfoo) #endif
Checking Whether or not another feature is required

Many times there might be a function x () (usually in another file) which are only needed if someone have requested  function y (). To test for the, use:

#ifdef netsnmp_feature_require_y netsnmp_feature_require (x)/* x () is implemented elsewhere, but we need it to implement Y () */#endif/* netsnmp_feature_require_y */
Checking Whether or not a dependent feature is available

Sometimes wish to advertise-a feature only if a subordinate feature are also available:

#include <net-snmp/net-snmp-config.h> #include <net-snmp/features.h>  #ifdef netsnmp_feature_has_ BAR netsnmp_feature_provide (foo) #endif/* Netsnmp_feature_has_bar */
Coding Using Features Support

To mark code as removable if a feature are unneeded, surround it with #ifndef markings:

#ifndef Netsnmp_feature_remove_foo/  * Normal FOO code */  #else/*! Netsnmp_feature_remove_foo *  /netsnmp_feature_unused (FOO);  #endif/*! Netsnmp_feature_remove_foo * *

A few important notes:

    • Always use the #ifndef version of checking. If the features.h fails to define anything, the feature would be included by default.
    • Always include the define name in comments after #else and #endif clauses. Later "Code-removal" scripts would depend upon it.
    • The netsnmp_feature_unused () macro is only needed if there are no code in the file left after the features has been remove D.
Checking for Feature support in Code

If you ' re writing code this depends on features but isn ' t "required" (ie, you used netsnmp_feature_want (foo)), th En can test for IT support:

#include <net-snmp/features.h>  #ifdef netsnmp_feature_has_foo/* include foo-specific coding here */#endif/* Netsnmp_feature_has_foo * *
Behind the Scenes

Behind The scenes, this implemented using a number of techniques:

  1. A set of Configure flags to enable minimalist mode and for selecting and removing specific features, as mentioned previously.
  2. When--with-minimalist was turned on, it adds a extra step to the compilation process: features which performs th E Rest of the steps below:
  3. compile-time feature-check and feature-remove scripts that:
    • feature-check:examines a Co De file for netsnmp_feature_xxx () lines and creates #define statements based on what it finds.
      • Requires that the code is examined in reverse order (eg, Agent/mibgroup/before Agent/helpers/and both befor e snmplib/).
    • Feature-remove:examines The results of the Feature-check output and creates. h files specific to Individ UAL code sections with netsnmp_feature_remove_xxx definitions or netsnmp_feature_has_xxx definitions .
      • includes a feature if anything requires or wants it
      • removes a feature if nothing requires it
      • removes a feature if something wants it, but--with-out-features requested it to be removed
      • Include s a feature if nothing required or wanted it--with-features requested it
  4. A net-snmp/features.h file "Does the right thing".
    • During the run of Feature-check It includes the definitions being produced by the checking
    • During compilation time, it includes the various feature.h files that have the netsnmp_feature_remove_xxx and Netsnmp_feature_has_xxx Tokens.
Notes on the end result
    1. ./configure; make, make install still works
    2. ./configure--with-minimalist; make, make install works
    3. For developers working in feature specific code, make run from the top level directory would continue to update th E generated Feature header files
      • But ... running make cleanfeatures first was safer if you ' re heavily modifying provide/require lines
      • Allows for run-time modifications without re-running configure
Real World ExamplesTls/dtls

In the new DTLS and TLS code we require a significant amount of certificate code.  Code is needed to manipulate certificate chains, load and unload directories of certificates, etc. This code was contained in SNMPLIB/CERT_UTIL.C.

To only include this code support when needed, SNMPLIB/CERT_UTIL.C have the following code:

#include <net-snmp/features.h>  netsnmp_feature_provide (cert_util)  #ifndef netsnmp_feature_remove_ Cert_util/* */#endif//Netsnmp_feature_remove_cert_util */

And in the snmplib/transports/snmptlstcpdomain.c and snmplib/transports/snmpdtlsudpdomain.c file:

#include <net-snmp/features.h>  netsnmp_feature_require (cert_util)

The end result is an if a user is not requiring the DTLS or TLS support and they ' ve requested --enable-minimalist then the entire CERT_UTIL.C functionality are not included. This is actually a very significant chunk of code.

finding Unused Code to Mark as a Feature

After building with your favorite set of configure options, you can see how many functions exist in the built. o Files usi ng This handy perl script:

Perl local/minimalist/find-unused-code-g

Which would produce a list of functions that were compiled if never referenced by another. o file, which indicates they ' re  Likely unused.  The-g switch would then grep any of the source code for source files, contain calls to those functions. This allows-know which file contains the function that should is marked as a feature, and which other files need to be modified to Netsnmp_feature_require () that function/feature.

Error: Net-snmp/net-snmp-features.h: no file or directory

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.