haiku/headers/os/net/NetworkRoute.h
Augustin Cavalier cbfbbf6d4d Change BObjectList to take "owning" as a template parameter and adjust all consumers.
Since BObjectList is a template class, this only breaks ABI where
BObjectList was exposed in public methods, and even then it's only
a name mangling break and we should be able to add compatibility
methods if necessary.

(The old "bool owning" member variable is left intact for ABI
compatibility, for the moment, though it's otherwise unused now.)

Tracker's PoseList is the only remaining type that has a "bool owning"
switch in the constructor rather than template parameters.

This should significantly improve the output of static code analysis
tools that previously detected list operations as causing use-after-frees
and double-frees, as well as make code maintenance easier by making it
easier to determine what list owns (or does not own) an object.
It should also be a minor performance optimization, since the branches
for calls to delete/free should now be optimized out altogether.

Still boots to desktop and Tracker, Deskbar, Debugger all tested
and verified as working.

Change-Id: If2a24a6f0d22e7a506ef554fcfdd328907279ed4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8915
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2025-02-06 00:06:32 +00:00

76 lines
2.0 KiB
C++

/*
* Copyright 2015, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _NETWORK_ROUTE_H
#define _NETWORK_ROUTE_H
#include <net/route.h>
#include <ObjectList.h>
class BNetworkRoute {
public:
BNetworkRoute();
~BNetworkRoute();
status_t SetTo(const BNetworkRoute& other);
status_t SetTo(const route_entry& routeEntry);
void Adopt(BNetworkRoute& other);
const route_entry& RouteEntry() const;
const sockaddr* Destination() const;
status_t SetDestination(const sockaddr& destination);
void UnsetDestination();
const sockaddr* Mask() const;
status_t SetMask(const sockaddr& mask);
void UnsetMask();
const sockaddr* Gateway() const;
status_t SetGateway(const sockaddr& gateway);
void UnsetGateway();
const sockaddr* Source() const;
status_t SetSource(const sockaddr& source);
void UnsetSource();
uint32 Flags() const;
void SetFlags(uint32 flags);
uint32 MTU() const;
void SetMTU(uint32 mtu);
int AddressFamily() const;
static status_t GetDefaultRoute(int family,
const char* interfaceName,
BNetworkRoute& route);
static status_t GetDefaultGateway(int family,
const char* interfaceName,
sockaddr& gateway);
static status_t GetRoutes(int family,
BObjectList<BNetworkRoute, true>& routes);
static status_t GetRoutes(int family, const char* interfaceName,
BObjectList<BNetworkRoute, true>& routes);
static status_t GetRoutes(int family, const char* interfaceName,
uint32 filterFlags,
BObjectList<BNetworkRoute, true>& routes);
private:
BNetworkRoute(const BNetworkRoute& other);
// unimplemented to disallow copying
status_t _AllocateAndSetAddress(const sockaddr& from,
sockaddr*& to);
void _FreeAndUnsetAddress(sockaddr*& address);
route_entry fRouteEntry;
};
#endif // _NETWORK_ROUTE_H