Move patty_ax25_if_stats accounting into drivers
Move patty_ax25_if_stats accounting into drivers to help provide a more consistent interface for accessing and incrementing interface statistics
This commit is contained in:
parent
9a1b163954
commit
dfd0978113
5 changed files with 39 additions and 15 deletions
|
@ -31,6 +31,8 @@ typedef void *(patty_ax25_if_driver_create)(void *);
|
||||||
|
|
||||||
typedef void (patty_ax25_if_driver_destroy)(void *);
|
typedef void (patty_ax25_if_driver_destroy)(void *);
|
||||||
|
|
||||||
|
typedef patty_ax25_if_stats *(patty_ax25_if_driver_stats)(void *);
|
||||||
|
|
||||||
typedef int (patty_ax25_if_driver_fd)(void *);
|
typedef int (patty_ax25_if_driver_fd)(void *);
|
||||||
|
|
||||||
typedef int (patty_ax25_if_driver_pending)(void *);
|
typedef int (patty_ax25_if_driver_pending)(void *);
|
||||||
|
@ -48,6 +50,7 @@ typedef ssize_t (patty_ax25_if_driver_send)(void *, const void *, size_t);
|
||||||
typedef struct _patty_ax25_if_driver {
|
typedef struct _patty_ax25_if_driver {
|
||||||
patty_ax25_if_driver_create *create;
|
patty_ax25_if_driver_create *create;
|
||||||
patty_ax25_if_driver_destroy *destroy;
|
patty_ax25_if_driver_destroy *destroy;
|
||||||
|
patty_ax25_if_driver_stats *stats;
|
||||||
patty_ax25_if_driver_fd *fd;
|
patty_ax25_if_driver_fd *fd;
|
||||||
patty_ax25_if_driver_pending *pending;
|
patty_ax25_if_driver_pending *pending;
|
||||||
patty_ax25_if_driver_fill *fill;
|
patty_ax25_if_driver_fill *fill;
|
||||||
|
@ -62,8 +65,6 @@ typedef void patty_ax25_if_phy;
|
||||||
typedef void patty_ax25_if_info;
|
typedef void patty_ax25_if_info;
|
||||||
|
|
||||||
typedef struct _patty_ax25_if {
|
typedef struct _patty_ax25_if {
|
||||||
patty_ax25_if_stats stats;
|
|
||||||
|
|
||||||
char name[8];
|
char name[8];
|
||||||
|
|
||||||
uint32_t flags_classes;
|
uint32_t flags_classes;
|
||||||
|
@ -107,6 +108,8 @@ int patty_ax25_if_promisc_add(patty_ax25_if *iface,
|
||||||
int patty_ax25_if_promisc_delete(patty_ax25_if *iface,
|
int patty_ax25_if_promisc_delete(patty_ax25_if *iface,
|
||||||
int fd);
|
int fd);
|
||||||
|
|
||||||
|
void patty_ax25_if_drop(patty_ax25_if *iface);
|
||||||
|
|
||||||
int patty_ax25_if_fd(patty_ax25_if *iface);
|
int patty_ax25_if_fd(patty_ax25_if *iface);
|
||||||
|
|
||||||
int patty_ax25_if_pending(patty_ax25_if *iface);
|
int patty_ax25_if_pending(patty_ax25_if *iface);
|
||||||
|
|
|
@ -18,6 +18,8 @@ enum state {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _patty_ax25_aprs_is {
|
struct _patty_ax25_aprs_is {
|
||||||
|
patty_ax25_if_stats stats;
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
char rx_buf[PATTY_AX25_APRS_IS_PACKET_MAX],
|
char rx_buf[PATTY_AX25_APRS_IS_PACKET_MAX],
|
||||||
|
@ -156,6 +158,10 @@ void patty_ax25_aprs_is_destroy(patty_ax25_aprs_is *aprs) {
|
||||||
free(aprs);
|
free(aprs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
patty_ax25_if_stats *patty_ax25_aprs_is_stats(patty_ax25_aprs_is *aprs) {
|
||||||
|
return &aprs->stats;
|
||||||
|
}
|
||||||
|
|
||||||
int patty_ax25_aprs_is_fd(patty_ax25_aprs_is *aprs) {
|
int patty_ax25_aprs_is_fd(patty_ax25_aprs_is *aprs) {
|
||||||
return aprs->fd;
|
return aprs->fd;
|
||||||
}
|
}
|
||||||
|
@ -402,6 +408,7 @@ patty_ax25_if_driver *patty_ax25_aprs_is_driver() {
|
||||||
static patty_ax25_if_driver driver = {
|
static patty_ax25_if_driver driver = {
|
||||||
.create = (patty_ax25_if_driver_create *)patty_ax25_aprs_is_new,
|
.create = (patty_ax25_if_driver_create *)patty_ax25_aprs_is_new,
|
||||||
.destroy = (patty_ax25_if_driver_destroy *)patty_ax25_aprs_is_destroy,
|
.destroy = (patty_ax25_if_driver_destroy *)patty_ax25_aprs_is_destroy,
|
||||||
|
.stats = (patty_ax25_if_driver_stats *)patty_ax25_aprs_is_stats,
|
||||||
.fd = (patty_ax25_if_driver_fd *)patty_ax25_aprs_is_fd,
|
.fd = (patty_ax25_if_driver_fd *)patty_ax25_aprs_is_fd,
|
||||||
.pending = (patty_ax25_if_driver_pending *)patty_ax25_aprs_is_pending,
|
.pending = (patty_ax25_if_driver_pending *)patty_ax25_aprs_is_pending,
|
||||||
.fill = (patty_ax25_if_driver_fill *)patty_ax25_aprs_is_fill,
|
.fill = (patty_ax25_if_driver_fill *)patty_ax25_aprs_is_fill,
|
||||||
|
|
20
src/if.c
20
src/if.c
|
@ -271,6 +271,10 @@ static int handle_promisc_frame(uint32_t key,
|
||||||
return patty_kiss_frame_send(fd, frame->buf, frame->len, 0);
|
return patty_kiss_frame_send(fd, frame->buf, frame->len, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void patty_ax25_if_drop(patty_ax25_if *iface) {
|
||||||
|
iface->driver->stats(iface->phy)->dropped++;
|
||||||
|
}
|
||||||
|
|
||||||
int patty_ax25_if_fd(patty_ax25_if *iface) {
|
int patty_ax25_if_fd(patty_ax25_if *iface) {
|
||||||
return iface->driver->fd(iface->phy);
|
return iface->driver->fd(iface->phy);
|
||||||
}
|
}
|
||||||
|
@ -301,8 +305,10 @@ ssize_t patty_ax25_if_flush(patty_ax25_if *iface) {
|
||||||
.iface = iface
|
.iface = iface
|
||||||
};
|
};
|
||||||
|
|
||||||
iface->stats.rx_frames++;
|
patty_ax25_if_stats *stats = iface->driver->stats(iface->phy);
|
||||||
iface->stats.rx_bytes += len;
|
|
||||||
|
stats->rx_frames++;
|
||||||
|
stats->rx_bytes += len;
|
||||||
|
|
||||||
if (patty_dict_each(iface->promisc_fds,
|
if (patty_dict_each(iface->promisc_fds,
|
||||||
handle_promisc_frame,
|
handle_promisc_frame,
|
||||||
|
@ -320,15 +326,19 @@ error_handle_promisc_frame:
|
||||||
ssize_t patty_ax25_if_send(patty_ax25_if *iface,
|
ssize_t patty_ax25_if_send(patty_ax25_if *iface,
|
||||||
const void *buf,
|
const void *buf,
|
||||||
size_t len) {
|
size_t len) {
|
||||||
ssize_t wrlen;
|
|
||||||
struct promisc_frame frame;
|
struct promisc_frame frame;
|
||||||
|
patty_ax25_if_stats *stats;
|
||||||
|
|
||||||
|
ssize_t wrlen;
|
||||||
|
|
||||||
if ((wrlen = iface->driver->send(iface->phy, buf, len)) < 0) {
|
if ((wrlen = iface->driver->send(iface->phy, buf, len)) < 0) {
|
||||||
goto error_driver_send;
|
goto error_driver_send;
|
||||||
}
|
}
|
||||||
|
|
||||||
iface->stats.tx_frames++;
|
stats = iface->driver->stats(iface->phy);
|
||||||
iface->stats.tx_bytes += wrlen;
|
|
||||||
|
stats->tx_frames++;
|
||||||
|
stats->tx_bytes += wrlen;
|
||||||
|
|
||||||
frame.buf = buf;
|
frame.buf = buf;
|
||||||
frame.len = wrlen;
|
frame.len = wrlen;
|
||||||
|
|
|
@ -2000,7 +2000,7 @@ static int handle_frame(patty_ax25_server *server,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_decode:
|
error_decode:
|
||||||
iface->stats.dropped++;
|
patty_ax25_if_drop(iface);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
18
src/tnc.c
18
src/tnc.c
|
@ -29,6 +29,8 @@ enum state {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _patty_kiss_tnc {
|
struct _patty_kiss_tnc {
|
||||||
|
patty_ax25_if_stats stats;
|
||||||
|
|
||||||
struct termios attrs,
|
struct termios attrs,
|
||||||
attrs_old;
|
attrs_old;
|
||||||
|
|
||||||
|
@ -42,8 +44,7 @@ struct _patty_kiss_tnc {
|
||||||
size_t bufsz,
|
size_t bufsz,
|
||||||
readlen,
|
readlen,
|
||||||
offset_i,
|
offset_i,
|
||||||
offset_o,
|
offset_o;
|
||||||
dropped;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
patty_kiss_tnc *patty_kiss_tnc_new(patty_kiss_tnc_info *info) {
|
patty_kiss_tnc *patty_kiss_tnc_new(patty_kiss_tnc_info *info) {
|
||||||
|
@ -144,12 +145,13 @@ patty_kiss_tnc *patty_kiss_tnc_new(patty_kiss_tnc_info *info) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(&tnc->stats, '\0', sizeof(tnc->stats));
|
||||||
|
|
||||||
tnc->opts = TNC_NONE;
|
tnc->opts = TNC_NONE;
|
||||||
tnc->state = KISS_NONE;
|
tnc->state = KISS_NONE;
|
||||||
tnc->bufsz = PATTY_KISS_TNC_BUFSZ;
|
tnc->bufsz = PATTY_KISS_TNC_BUFSZ;
|
||||||
tnc->offset_i = 0;
|
tnc->offset_i = 0;
|
||||||
tnc->offset_o = 0;
|
tnc->offset_o = 0;
|
||||||
tnc->dropped = 0;
|
|
||||||
tnc->readlen = 0;
|
tnc->readlen = 0;
|
||||||
|
|
||||||
return tnc;
|
return tnc;
|
||||||
|
@ -189,6 +191,10 @@ void patty_kiss_tnc_destroy(patty_kiss_tnc *tnc) {
|
||||||
free(tnc);
|
free(tnc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
patty_ax25_if_stats *patty_kiss_tnc_stats(patty_kiss_tnc *tnc) {
|
||||||
|
return &tnc->stats;
|
||||||
|
}
|
||||||
|
|
||||||
int patty_kiss_tnc_fd(patty_kiss_tnc *tnc) {
|
int patty_kiss_tnc_fd(patty_kiss_tnc *tnc) {
|
||||||
return tnc->fd;
|
return tnc->fd;
|
||||||
}
|
}
|
||||||
|
@ -198,11 +204,8 @@ static void tnc_drop(patty_kiss_tnc *tnc) {
|
||||||
tnc->offset_i = 0;
|
tnc->offset_i = 0;
|
||||||
tnc->offset_o = 0;
|
tnc->offset_o = 0;
|
||||||
tnc->readlen = 0;
|
tnc->readlen = 0;
|
||||||
tnc->dropped++;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t patty_kiss_tnc_dropped(patty_kiss_tnc *tnc) {
|
tnc->stats.dropped++;
|
||||||
return tnc->dropped;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int patty_kiss_tnc_pending(patty_kiss_tnc *tnc) {
|
int patty_kiss_tnc_pending(patty_kiss_tnc *tnc) {
|
||||||
|
@ -341,6 +344,7 @@ patty_ax25_if_driver *patty_kiss_tnc_driver() {
|
||||||
static patty_ax25_if_driver driver = {
|
static patty_ax25_if_driver driver = {
|
||||||
.create = (patty_ax25_if_driver_create *)patty_kiss_tnc_new,
|
.create = (patty_ax25_if_driver_create *)patty_kiss_tnc_new,
|
||||||
.destroy = (patty_ax25_if_driver_destroy *)patty_kiss_tnc_destroy,
|
.destroy = (patty_ax25_if_driver_destroy *)patty_kiss_tnc_destroy,
|
||||||
|
.stats = (patty_ax25_if_driver_stats *)patty_kiss_tnc_stats,
|
||||||
.fd = (patty_ax25_if_driver_fd *)patty_kiss_tnc_fd,
|
.fd = (patty_ax25_if_driver_fd *)patty_kiss_tnc_fd,
|
||||||
.pending = (patty_ax25_if_driver_pending *)patty_kiss_tnc_pending,
|
.pending = (patty_ax25_if_driver_pending *)patty_kiss_tnc_pending,
|
||||||
.fill = (patty_ax25_if_driver_fill *)patty_kiss_tnc_fill,
|
.fill = (patty_ax25_if_driver_fill *)patty_kiss_tnc_fill,
|
||||||
|
|
Loading…
Add table
Reference in a new issue