Files
amnezia-client/client/platforms/macos/daemon/macosroutemonitor.h
T

68 lines
2.0 KiB
C++
Raw Normal View History

2021-10-23 04:26:47 -07:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef MACOSROUTEMONITOR_H
#define MACOSROUTEMONITOR_H
#include <QByteArray>
2023-07-15 14:19:48 -07:00
#include <QHostAddress>
2021-10-23 04:26:47 -07:00
#include <QList>
#include <QObject>
#include <QSocketNotifier>
2023-07-15 14:19:48 -07:00
#include "ipaddress.h"
2021-10-23 04:26:47 -07:00
struct if_msghdr;
struct rt_msghdr;
struct sockaddr;
class MacosRouteMonitor final : public QObject {
Q_OBJECT
public:
MacosRouteMonitor(const QString& ifname, QObject* parent = nullptr);
~MacosRouteMonitor();
2025-01-13 21:45:06 +07:00
bool insertRoute(const IPAddress& prefix, int flags = 0);
bool deleteRoute(const IPAddress& prefix, int flags = 0);
2021-10-23 04:26:47 -07:00
int interfaceFlags() { return m_ifflags; }
bool addExclusionRoute(const IPAddress& prefix);
bool deleteExclusionRoute(const IPAddress& prefix);
2023-07-15 14:19:48 -07:00
void flushExclusionRoutes();
2021-10-23 04:26:47 -07:00
private:
void handleRtmDelete(const struct rt_msghdr* msg, const QByteArray& payload);
2023-07-15 14:19:48 -07:00
void handleRtmUpdate(const struct rt_msghdr* msg, const QByteArray& payload);
2021-10-23 04:26:47 -07:00
void handleIfaceInfo(const struct if_msghdr* msg, const QByteArray& payload);
bool rtmSendRoute(int action, const IPAddress& prefix, unsigned int ifindex,
2025-01-13 21:45:06 +07:00
const void* gateway, int flags = 0);
2023-07-15 14:19:48 -07:00
bool rtmFetchRoutes(int family);
2021-10-23 04:26:47 -07:00
static void rtmAppendAddr(struct rt_msghdr* rtm, size_t maxlen, int rtaddr,
const void* sa);
static QList<QByteArray> parseAddrList(const QByteArray& data);
private slots:
void rtsockReady();
private:
static QString addrToString(const struct sockaddr* sa);
static QString addrToString(const QByteArray& data);
QList<IPAddress> m_exclusionRoutes;
2023-07-15 14:19:48 -07:00
QByteArray m_defaultGatewayIpv4;
QByteArray m_defaultGatewayIpv6;
unsigned int m_defaultIfindexIpv4 = 0;
unsigned int m_defaultIfindexIpv6 = 0;
2021-10-23 04:26:47 -07:00
QString m_ifname;
2023-07-15 14:19:48 -07:00
unsigned int m_ifindex = 0;
2021-10-23 04:26:47 -07:00
int m_ifflags = 0;
int m_rtsock = -1;
int m_rtseq = 0;
QSocketNotifier* m_notifier = nullptr;
};
#endif // MACOSROUTEMONITOR_H